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

标签 javascript angularjs controller mean-stack angularjs-routing

我有一个函数

        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/

相关文章:

javascript - 使用 beforeShow() 在日期选择器中添加类

php - 在 JavaScript 中解密 PHP AES/CBC 加密字符串

JavaScript 事件 onfocus 和 onblur

javascript - 这个命名的自调用函数如何传递参数?

php - CakePHP 清理实用程序

javascript - 如何在窗口监听器函数中调用 Controller 函数

php - 在单个数组中返回多个 SELECT 查询

css - 除非手动修改输入,否则为什么 ng-class 不求值?

ruby-on-rails - [ rails ] : Display a multiple category checkbox in a product form

controller - iPad 上 UIDocumentInteractionController : presentPreviewAnimated is not pushed into the navigation stack 的可能错误