From the course: Upgrading to Angular 1.6

Unlock the full course today

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

Convert a directive

Convert a directive - Angular Tutorial

From the course: Upgrading to Angular 1.6

Start my 1-month free trial

Convert a directive

- [Instructor] Let's see how directive can be converted into a component. Open todo.js in the exercise files. The first step in the conversion is, not surprisingly, to change the code to use the component function instead of directive. Next, notice that components are defined using plain objects. There's no need for a factory function. If the directive had any dependencies injected, they could be easily moved to the controller itself. I now go over the definition object, and change some attributes. First, I rename scope to bindings. This is the name used for components. Bind to controller is always on for components, and is no longer needed. Controllers that use $ctrl as their name don't need to specify it anymore. And since components only work on the element level, it's safe to delete the restrict setting. And that's it. This is now our real and working component.

Contents