gpt4 book ai didi

javascript - 在angularjs中调用 Controller 时如何加载函数

转载 作者:行者123 更新时间:2023-11-28 04:57:06 24 4
gpt4 key购买 nike

我有一个函数

        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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com