<ul>
<li><input placeholder="Give me a name!" ng-model="world" /></li>
</ul>
<h3>Hello {{world}}!</h3>
<ul>
<li ng-repeat="item in model.listItems">{{item}}</li>
</ul>
$scope.model = {
listItems: ['Item one',
'Item two',
'Banana']
}
myModule.directive('directiveName', function factory(injectables) {
var directiveDefinitionObject = {
priority: 0,
template: '',
templateUrl: 'directive.html',
replace: false,
transclude: false,
restrict: 'A',
scope: false,
compile: function compile(tElement, tAttrs, transclude) {
return {
pre: function preLink(scope, iElement, iAttrs, controller) { ... },
post: function postLink(scope, iElement, iAttrs, controller) { ... }
}
},
link: function postLink(scope, iElement, iAttrs) { ... }
};
return directiveDefinitionObject;
});
<textarea markdown></textarea>
<div class="preview"></div>
angular.module('presentationApp.directives', []).
directive('markdown', function() {
var converter = new Showdown.converter();
return {
restrict: 'A',
link: function(scope, element, attrs) {
element.bind('blur keyup change', function() {
var htmlText = converter.makeHtml(element.val());
$('.preview').html(htmlText);
});
}
}
});