<!-- View without ControllerAs syntax that has nested scopes.-->
<div ng-controller="Order">
<input type="text" ng-model="orderTotal" />
<div ng-if="showDetails">
<input type="text" ng-model="orderTotal" />
</div>
</div>
You can avoid all of that mess by using ControllerAs syntax:
<!-- View with nested scopes, but with ControllerAs.-->
<div ng-controller="Order as vm">
<input type="text" ng-model="vm.orderTotal" />
<div ng-if="showDetails">
<input type="text" ng-model="vm.orderTotal" />
</div>
</div>
Now the two models explicitly share the same scope of the controller’s alias,
vm
, and we’ve tamed the scope craziness.
No comments:
Post a Comment