One of the most appreciated features of AngularJs is scopes, at the same time scopes will give you nightmare if don’t avoid unwanted scopes from creating.
ng-model data scope is one of the main challenge you get quite often. While working with
ng-model data, new unwanted scope can be created by
ng-if procedures. Let’s look at the below example
In the above example, the scope is created separately for
outerScope, so it does not share it’s data. We can handle this with single scope - One way to do this is we can use “Controller As” approach instead of using scope as a container for all data and functions.
One catchy solution is to keep everything in objects as shown is below example
Let me what methods/best practices you follow to avoid unwanted scopes from creating in AngularJS.