Binding Properties to Directives

Learn how to bind properties to directives to make them more dynamic.

We have a directive that changes the color of the text to which it’s applied. It’s not really what we were going for. Let’s modify it to add a class to an element. We want to be able to add any class we’d like.

Accepting data from the component

Luckily, we already know how to accept data from one part of the application to another. We can use the @Input() decorator to accept data from a component.

In the class.directive.ts file, we’ll update the class to the following:

Get hands-on with 1200+ tech skills courses.