O'Reilly logo

AngularJS Directives by Alex Vanston

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Scope = true

The first step down the path of limiting, or modularizing, your scope is setting its value to true. In this case, a new inherited scope is actually generated, much like the behavior when nesting controllers. This type of scoping for a directive is by far the easiest to understand and operate within, as you still have read access to all of the parent scope's values, but it's less likely that you'll accidentally change the data in the rest of the application. For this reason, I usually recommend setting scope to true from the beginning, unless you have a strong reason to do otherwise.

To help clarify the difference of this type of scoping, let's revisit our previous example. This time, the scope section of our definition object will ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required