从子州访问子州

时间:2016-12-27 22:28:22

标签: javascript angularjs angularjs-scope angular-ui-router

我想从子状态访问子状态但我得到:angular.js:14195 Error: Could not resolve '#/projects/detailProject' from state 'projects.list

这些是州:<​​/ strong>

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',
            sidebarMeta: {
                icon: 'ion-compose',
                order: 250,
            },
        })
        .state('projects.add', {
            url: '/add',
            templateUrl: 'app/pages/projects/add/projects.html',
            title: 'Ajouter un projet',
            sidebarMeta: {
                order: 800,
            },
        })
        .state('projects.list', {
            url: '/list',
            params : { projectId : null},
            templateUrl: 'app/pages/projects/list/listProjects.html',
            title: 'List',
            sidebarMeta: {
                order: 900,
            },
        })
         .state('projects.detail', {
             url: '/detail',
             templateUrl: 'app/pages/projects/detail/detailProject.html',
             title: 'Detail du projet',
        });
    $urlRouterProvider.when('/projects','/projects/list');
}

我正试图访问儿童状态槽:

<button type="button" id="Edit" name="Edit" ng-click="goToPath('#/projects/detailProject', p.id)"class="btn btn-primary btn-raised">Editer</button></div>

`这是我的 goToPath 方法:

$scope.goToPath = function ( path, pid ) {
    $scope.pid = pid;
    $state.go(path, {projectId : pid} );
};

感谢。

1 个答案:

答案 0 :(得分:0)

使用UI-Router,您可以定义状态并导航到这些状态。所以你的$state.go应该得到一个状态,而不是一个路径。

<button ng-click="goToPath('projects.detail', p.id)">Editer</button>