From the course: Angular Essential Training (2019)

Unlock the full course today

Join today to access over 22,400 courses taught by industry experts or purchase this course individually.

Attribute directives: Custom

Attribute directives: Custom - Angular Tutorial

From the course: Angular Essential Training (2019)

Start my 1-month free trial

Attribute directives: Custom

- [Demonstrator] Okay, that's build a custom attribute directive. This attribute directive will handle setting a class on the media item element. If it has been set to a favorite or not, we start by creating a new file named favorite.directive.ts And in there we bring in the directive decorator with an import statement from the angular core scoped package. Then we use the @directive decorator and pass it in object literal for the directive metadata The selector value is going to be a string with square brackets around MWfavorite. We use the square brackets in this string because we want the selector to find a match on an element attribute and selectors are similar to the construct for a CSS selector. The MW prefix on the name is our own creation here, short for media watcher, the same prefix we use for component selectors. It's recommended to use a domain prefix on directive selectors for directives that you…

Contents