2015-10-15 113 views
0

我采用了棱角分明的UI路由器来创建这样URL变化不触发对角UI路由器状态变化

routes.$inject = ['$stateProvider']; 

export default function routes($stateProvider) { 
    $stateProvider 
    .state('home', { 
     url: '/', 
     template: require('./home.html'), 
     controller: 'HomeController', 
     controllerAs: 'home' 
    }) 

在HomeController的家庭路线,我进口,提供博客流服务帖子。因此,在./home.html模板,我通过这样的职位的数组迭代,创建链接每篇文章

<span ng-repeat="post in home.posts"> 

     <a ui-sref="home.detail({postId:post.id})">{{post.title.rendered}}</a> 

    </span> 

你可以从链接看到,我期待的链接的点击进行处理由home.detail状态。在路由器中,我这样做,期待每个帖子都有一个url(当我点击链接时),例如http://localhost:8888/1http://localhost:8888/4。但是,当我单击链接时,url会更改,但./post.html模板不会加载,并且以下控制器代码中的日志语句不会运行。控制台中没有错误。

问题:为什么路由器代码处理点击单个链接(加载新模板,记录stateParams)没有运行时,我点击链接到帖子(但URL更改)?

$stateProvider 
    .state('home', { 
     url: '/', 
     template: require('./home.html'), 
     controller: 'HomeController', 
     controllerAs: 'home' 
    }) 
    .state('home.detail', { 


     url: '{postId:[0-9]{1,4}}', 
     template: require('./post.html'), 
     controller: ['$scope', '$stateParams', 
      function ( $scope, $stateParams) { 
       console.log($scope, "$scope", $stateParams, "$stateParams"); 
       $scope.post = $stateParams; 

      }], 

回答

1

您的父母国家需要一个ui视图。从UI路由器的documentation

子状态将加载他们的模板到他们父母的UI视图。

相关问题