AngularJS - Simple Directive Use
by michaelnatkin
HTML
<link rel="stylesheet" href="http://twitter.github.com/bootstrap/assets/css/bootstrap.css">
<div ng-app="myApp">
<div ng-controller="BugCtrl">
<div to-infinity value="getValue()"></div>
</div>
</div>
CSS
strong {
font-weight: 900;
}
JavaScript
angular.module('fun', [])
angular.module('myApp', ['fun']).directive('toInfinity',
function($sce) {
return {
scope: {'value' : '='},
restrict: 'A',
template: "<p ng-bind-html='value'></p>",
};
}
);
function BugCtrl($scope, $sce) {
$scope.getValue = function() {
return $sce.trustAsHtml('<h1>badass</h1>');
}
}