Angular JS: Directives
Read Time - 2 minsDirectives are if not the most relevant component of Angular JS, a very essential one. It affords the ability to basically extend HTML and makes code more readable.
Directives are also reusable hence creating a more cleaner, easy to debug and easier to test codebase. Consider the code below:
Directives basically tell the browser that a new element has been added.
Restrict signals how a particular element is to be used in the browser Restrictions can be set to
- E (as in this case) matches only element name
- A - matches only element name
- C - matches only class name
- M - matches only comment
Scope signals that information will be passed into this directive through the attribute. Hence info: ‘=’ tells the directive to scan through the
Scope:{} means is set to empty
The templateUrl is then used to specify the html file used to display the date. Typical html
Assuming the scopes have been defined in the MainController eg.
Then data will be called and displayed in the format as defined in cars.html