zoukankan      html  css  js  c++  java
  • $stateProvider resovle 无法找到的原因

    $stateProvider 在写resolve的时候,也要写上controller,不能直接在页面上用ng-controller 来指定!!!![允悲]

    不然的话,就是报依赖注入异常,找不到该provider。

    事情经过:

    今天在写$stateProvider resolve的时候一直报controller 无法找到该provider

    错误代码如下:

    // Router 路由层
    var articleModel = angular.module('SEProjectApp.articles').config(['$stateProvider',
        function($stateProvider) {
            // Articles state routing
            $stateProvider
                .state('app.articles', {
                    abstract: true,
                    url: '/articles',
                    template: '<ui-view/>'
                })
                .state('app.articles.list', {
                    url: '/list',
                    templateUrl: 'modules/articles/client/views/list-articles.client.view.html',
                    resolve: {
                        simpleObj: function() {
                            return { value: 'simple!' };
                        }
                    }
                })
    
        }
    
    ]);
    // Controller 层
    angular.module('SEProjectApp.articles').controller('ArticlesController', ["simpleObj", function (simpleObj) {
     .... 略
    }]);
    // 页面代码
    <section ng-controller="ArticlesController" ng-init="find()">
    .... 略
    </section>

    后来,在router层的state中指定 controller: 'ArticlesController' 并且将页面中的ng-controller的指令去掉,才成功运行。

  • 相关阅读:
    python中几种数据类型常用的方法
    WSGI
    从开学到初赛的一些个人总结
    CSP-S2020 浙江 游记
    CF1416D Graph and Queries
    单次期望 O(1) 的RMQ
    P3177 [HAOI2015]树上染色
    CF835F Roads in the Kingdom/P1399 [NOI2013]快餐店
    P4381 [IOI2008]Island
    P5655 基础数论函数练习题
  • 原文地址:https://www.cnblogs.com/JamKong/p/8618716.html
Copyright © 2011-2022 走看看