我有一个函数
state('showList', {
url: '/listView',
templateUrl: 'app/templates/showlist.html',
controller: "showListCtrl"
}).
我的 Controller ,
.controller('overViewCtrl', function ($scope) {
$scope.getList = function(){
//A http call
}
});
当我的路线更改为“/listView”时,将调用 overView Controller ,但不会调用函数 getList(),但在刷新页面时会调用我。任何人都可以帮助我。我只想调用它 Controller 加载后立即运行。谢谢。
当我的路线更改为“/listview”时
最佳答案
你可以在函数外部声明里面的代码,
.controller('overViewCtrl', function ($scope)
//put it here without a function
});
或者可以在页面使用ng-init来调用该函数
关于javascript - 在angularjs中调用 Controller 时如何加载函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42459850/