Skip to content

Instantly share code, notes, and snippets.

@superchris
Created May 4, 2015 22:00
Show Gist options
  • Save superchris/2effea3e840459611a85 to your computer and use it in GitHub Desktop.
Save superchris/2effea3e840459611a85 to your computer and use it in GitHub Desktop.
JS Bin uppercase directive // source http://jsbin.com/ladato
<!DOCTYPE html>
<html ng-app="app">
<head>
<meta name="description" content="uppercase directive" />
<script src="http://code.jquery.com/jquery.min.js"></script>
<link href="http://getbootstrap.com/2.3.2/assets/css/bootstrap.css" rel="stylesheet" type="text/css" />
<link href="http://getbootstrap.com/2.3.2/assets/css/bootstrap-responsive.css" rel="stylesheet" type="text/css" />
<script src="http://getbootstrap.com/2.3.2/assets/js/bootstrap.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.14/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.14/angular-sanitize.js"></script>
<meta charset=utf-8 />
<title>JS Bin</title>
</head>
<body ng-controller="main">
<textarea ng-model="text"></textarea>
<upper-case text="text" click-handler="alertHi()"></upper-case>
<script id="jsbin-javascript">
var app = angular.module("app", ["ngSanitize"]);
app.controller("main", function($scope) {
$scope.text = "small things";
$scope.alertHi = function() { alert("hi!"); };
});
app.directive("upperCase", function($sce){
return {
restrict: "E",
template: "<div><div ng-bind-html='value'></div><input type='button' value='click me' ng-click='clickHandler()' /></div>",
replace: true,
scope: {
text: "=",
clickHandler: "&"
},
link: function(scope, element, attrs) {
scope.$watch("text", function(text) {
scope.value = text.toUpperCase();
})
}
};
});
</script>
<script id="jsbin-source-javascript" type="text/javascript">var app = angular.module("app", ["ngSanitize"]);
app.controller("main", function($scope) {
$scope.text = "small things";
$scope.alertHi = function() { alert("hi!"); };
});
app.directive("upperCase", function($sce){
return {
restrict: "E",
template: "<div><div ng-bind-html='value'></div><input type='button' value='click me' ng-click='clickHandler()' /></div>",
replace: true,
scope: {
text: "=",
clickHandler: "&"
},
link: function(scope, element, attrs) {
scope.$watch("text", function(text) {
scope.value = text.toUpperCase();
})
}
};
});</script></body>
</html>
var app = angular.module("app", ["ngSanitize"]);
app.controller("main", function($scope) {
$scope.text = "small things";
$scope.alertHi = function() { alert("hi!"); };
});
app.directive("upperCase", function($sce){
return {
restrict: "E",
template: "<div><div ng-bind-html='value'></div><input type='button' value='click me' ng-click='clickHandler()' /></div>",
replace: true,
scope: {
text: "=",
clickHandler: "&"
},
link: function(scope, element, attrs) {
scope.$watch("text", function(text) {
scope.value = text.toUpperCase();
})
}
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment