解决方法
I want to ask that if the same controller is binded at different pages does those pages share the same scope variable or they have their own isolated scope? Remember both of the pages are using the same controller.
是的,我在这里回应其他人的想法.如果您对任意数量的页面使用相同的控制器,则每个页面的范围将保持不变.除非不更改范围,否则该值将保持初始化期间的值.
例如.你的控制器如下
myApp.controller('FirstCtrl',function( $scope){ $scope.myVar = 'this is my scope'; });
如果您对两个页面使用相同的控制器,那么第一页和第二页将具有相同的myVar值.因此,在一页中的html下面
<div ng-model="myVar"></div>
在第二页的html下面
<span ng-model="myVar"></span>
将显示为
<div ng-model="myVar">this is my scope</div>
和
<span ng-model="myVar">this is my scope</span>
分别.
鉴于此,我想补充说,也可以使用$emit,$broadcast和$on在不同的控制器之间共享$scope.
在http://www.dotnet-tricks.com/Tutorial/angularjs/HM0L291214-Understanding- $emit,– $broadcast-and- $on-in-AngularJS.html上阅读更多相关信息
希望这可以帮助.