Skip to content

Instantly share code, notes, and snippets.

@xuyuanme
Last active August 29, 2015 13:56
Show Gist options
  • Save xuyuanme/9032862 to your computer and use it in GitHub Desktop.
Save xuyuanme/9032862 to your computer and use it in GitHub Desktop.
angular.module("alert-directive", [])
.directive('alert', function () {
return {
restrict: 'EA', // support to be used as an element or an attribute
replace: true, // tells the compiler to replace the original directive's element with the template given by the template field
template: '<div class="alert alert-{{type || \'info\'}}">' +
'<button type="button" class="close" ng-click="close()">&times;</button>' +
'<div ng-transclude></div>' + // the ng-transclude directive gets the transcluded elements and appends them to the element in the template on which it appears
'</div>',
transclude: true, // tells the compiler to extract the contents of the original <alert> element and make them available to be transcluded into the template
scope: { // create an isolated scope
type: '=', // the = symbol indicates that AngularJS should keep the expression in the specified attribute and the value on the isolated scope in sync with each other
close: '&' // the & symbol indicates that the expression provided in the attribute on the element will be made available on the scope as a function
}
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment