的init()不angularJs要求第二次起 [英] init() is not calling for second time onwards in angularJs
问题描述
我有类似下面。我结合国家下拉。
I've something like below. I am binding countries to a dropdown .
在下拉菜单的变化,我可以显示不同的看法。
On dropdown change i've to display different views.
$scope.countries = [{id : 1, name : 'USA1', pageName : 'USA'}, {id : 2, name : 'USA2', pageName : 'USA'},{id : 3, name : 'India3', pageName : 'India'}, {id : 4, name : 'India4', pageName : 'India'}];
<select class="form-control" ng-model="selectedCountry" ng-options="country as country.name for country in countries">
<option value="">Select Country</option>
</select>
-
<div ng-include="'views/'+selectedCountry.pageName+'.html'"></div>
我init()方法在两个usaController&放大器; indiaController。
现在,
i've init() method in both usaController & indiaController. Now,
- 如果我选择USA1然后usaController - 的init() - 调用
- 如果我选择India1然后indiaController - 的init() - 调用
- 如果我选择USA2随后的init() - 并没有叫。 - 问题
观察:如果选择X1国家,那么X.html将加载。如果选择X2则X.html不爽快(的init()不调用)。如果我选择Y1国家则Y.html负荷。现在,如果我选择X1和X2是正常加载。
让说,我选择X2这里..做工精细。再次,如果我选择X1,然后同样的问题重复。
Observation: If select X1 country then X.html will load. If select X2 then X.html is not refreshing ( init() is not calling). If i select Y1 country then Y.html loads. Now if i select X1 or X2 it is loading properly. Let say i selected X2 here.. working fine. again if i select X1 then same problem repeats.
我的init()的控制器功能看起来像下面。
My init() function in controller looks like below.
(function init() {
getSomeThing();
})();
任何解决办法吗?
Any solution please?
推荐答案
尝试使用
<div ng-include="'views/'+selectedCountry.name+'.html'" onload="getSomeThing()"></div>
防爆pression 的onload里面
属性应该评估时,一个新的部分被加载。
Expression inside onload
attribute should evaluate when a new partial is loaded.
这篇关于的init()不angularJs要求第二次起的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!