2016-09-29 56 views

回答

0

当你定义的路由/状态(取决于您是否使用ngRouter/uiRouter),只需添加一个面包屑对象,以它像这样:

$stateProvider 
    .state('courses', { 
     url: '/create', 
     template: ...., 
     controller: ...., 
     breadcrumbs: [ 
     { 
      name: Home, 
      url: '/home' 
     }, 
     { 
      name: Create User, 
      url: '/create' 
     } 
     ] 
    }) 

而在你的控制器,注入breadcrumbs作为依赖,和ng-repeat了他们对你的模板

//Controller 
.controller('mycontroller', function mycontroller($scope, breadcrumbs) { 
    $scope.breadcrumbs = breadcrumbs; 
} 



//Template 
<span class="breadcrumbs"> 
    <a ng-repeat="breadcrumb in breadcrumbs" ng-bind="::breadcrumb.name" href="{{breadcrumb.url}}"></a> 
</span> 
+0

感谢您回应,将它的工作当我的父母状态改变时,是否有可能获得动态状态,因为我不知道哪个状态会在我的应用中下一个 –

+0

我有一个主模块和几个子模块les和在每个子模块中,我有他们每个人的状态 –

+0

甚至更​​多我不确定以前的状态,哪一个将是我以前的状态 –

0

我已经使用状态改变的成功来获得当前和以前的状态 和我需要的是工作一样。

以下是我在主模块JS做了(在我的情况app.js):

angular.module('app').run(['$rootScope', function ($rootScope) { 
    $rootScope.$on('$stateChangeSuccess', function (event, toState, toParams, fromState, fromParams, error) { 
//goes here your code to manage states and their respective labels 
      $rootScope.breadcrumbStates = []; 
      $rootScope.breadcrumbLabels = []; 
      $rootScope.breadcrumbStates.push(fromState.name); 
      $rootScope.breadcrumbStates.push(toState.name); 
      $rootScope.breadcrumbLabels.push(fromState.label); 
      $rootScope.breadcrumbLabels.push(toState.label); 
}]); 

HTML

<ul class="breadcrumb"> 
     <li ng-repeat="breadcrumb in breadcrumbStates track by $index">    
       <a ui-sref="{{breadcrumb}}">{{breadcrumbLabels[$index]}}</a> 
     </li> 
    </ul>