1.

What does the following code do? What are the permitted values of the restrict attribute?

Answer»

app.directive('myFirstDirective', function() { return { restrict: 'E', SCOPE: { directiveInfo: '=directiveInfo' }, templateUrl: 'my-first-directive.html' };});

  • In the given piece of CODE, we have defined a custom directive called “myFirstDirective”. Based on the value of restrict, we can say that the directive is RESTRICTED only to the element names. The directive has an isolated scope which has a property called “directiveInfo” that will be getting its value from the “directiveInfo” attribute of the element directive. The view or the template URL used for making the directive work is “my-first-directive.html”.
  • Following are the possible values of the restrict attribute in AngularJS directives:
    • ‘A’ - attribute names are MATCHED.
    • ‘E’ - element names are matched.
    • ‘C’ - class names are matched.
    • ‘M’ - only comments are matched.


Discussion

No Comment Found