What is the use of restrict and template property when creating custom directives?

devquora
devquora

Posted On: Feb 22, 2018

 

Custom directives gives us the ability to create our own directives. Its restriction property helps us to enforce the decision of how this custom directive should be used. The restriction property takes four values as input:

  • E- If E is the value for the restriction property, the directive can only be used as an element in an html page,
  • A- If A is used as a value, the directive can be used as an attribute in any html tag,
  • C-If C is used, the directive gets triggered if same CSS class is used,
  • M-If M is used, the directive gets triggered if same comment is used.

These four values can also be combined and used, for example : ‘EA’ if provided as a value will allow the directive to be used as an element as well as an attribute. ‘EAC’ can also be set as a value for restrict. “template” property is used in a directive if you have to inject a template in your html page.”template” property takes an html template as an input. The main objective of this property is to reduce the re-work involved in writing same code again and again.

    Related Questions

    Please Login or Register to leave a response.

    Related Questions

    AngularJS Basic Interview Questions

    What is AngularJS?

    AngularJS is a javascript framework which helps in developing web applications in MVC architectural pattern & SPA or..

    AngularJS Basic Interview Questions

    What are angular directives?

    Angular directives are the attributes which are decorated on the html tags or elements of an html page. Directives have ..

    AngularJS Basic Interview Questions

    What are custom directives?

    Angular provides the ability to create our own directives to implement our own custom templates or logic in our web appl..