Skip to content

Instantly share code, notes, and snippets.

@MilanGrubnic70
Created March 3, 2016 03:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MilanGrubnic70/bd5403f62f5eaf303ff0 to your computer and use it in GitHub Desktop.
Save MilanGrubnic70/bd5403f62f5eaf303ff0 to your computer and use it in GitHub Desktop.
Angular Directives
app.directive('appInfo', function() {
return {
restrict: 'E',
scope: {
info: '='
},
templateUrl: 'js/directives/appInfo.html'
};
});
First in js/directives/appInfo.js, we made a new directive. We used app.directive to create a new directive named 'appInfo'. It returns an object with three options:
restrict: specifies how the directive will be used in the view. The 'E' means it will be used as a new HTML element.
scope: specifies that we will pass information into this directive through an attribute named info.
The = tells the directive to look for an attribute named info in the <app-info> element, like this:
<app-info info="shutterbugg"></app-info>
The data in info becomes available to use in the template given by templateURL.
templateUrl: specifies the HTML to use in order to display the data in scope.info. Here we use the HTML in js/directives/appInfo.html.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment