子状态解析在父控制器中注入

时间:2017-01-11 17:01:36

标签: javascript angularjs angular-ui-router

我有这个状态confg:

function routeConfig($stateProvider, $urlRouterProvider) {
    $stateProvider
        .state('projects', {
            url: '/projects',
            template : '<ui-view  autoscroll="true" autoscroll-body-top></ui-view>',
            abstract: true,
            title: 'Les projets',
            controller : 'ProjectController',
        }) .state('projects.add', {
            url: '/add',
            templateUrl: 'http://localhost:8080/gestionprojet/projects',
            title: 'Ajouter un projet',
        })
         .state('projects.detail', {
             url: '/detail',
             params : { projectId : null},
             templateUrl: 'http://localhost:8080/gestionprojet/detailProject',
             resolve : {
                 project: function (projectFactory, $stateParams) {
                     return projectFactory.getProject($stateParams.projectId);
                 },
                 projectTasks : function (projectFactory, $stateParams) {
                     return projectFactory.getProjectTasks($stateParams.projectId);
                 } 
             },
             title: 'Detail du projet',
        });
}

并在我的控制器中:

angular.module('BlurAdmin.pages.projects')
.controller('ProjectController', ProjectController);

function ProjectController($state, $stateParams, $log, $scope, projectFactory, taskFactory, project, projectTasks) { ... }

如果我转到project.add

,我会收到此错误消息
  

未知提供者:projectProvider&lt; - project&lt; - ProjectController

如何解决这个问题?谢谢。

1 个答案:

答案 0 :(得分:1)

嵌套已解析的变量无法注入父控制器。见here