How to use ncy-breadcrumb in child state of abstract parent

别说谁变了你拦得住时间么 提交于 2019-12-24 17:37:30

问题


I am new to AngularJS and I used ncy-breadcrumb for my AngularJS project. There is an abstract true parent state and two child states of it. I used these child states for tabs. But I couldn't find a way to show these states in the breadcrumb dynamically. The only thing I can do is hardcode one child state name as parent in other state. But I need a solution to display these child states in collectionsWorkPage state dynamically.

.state('collectionsLibrary', {
   url: '/headquarters/collections-library/',
   templateUrl: 'app/views/collectionsLibrary/base.html',
   controller: 'CollectionsLibraryBaseController',
   ncyBreadcrumb: {
      label: 'Collections Library',
      parent: 'headquarters'
   },
   abstract: true,
   resolve: {
      controller: function ($q) {
         var deferred = $q.defer();
         require(['controllers/collectionsLibrary/CollectionsLibraryBaseController'], function () {
            deferred.resolve();
         });
         return deferred.promise;
      }
   }
   })

.state('collectionsLibrary.available', {
   url: 'available/',
   templateUrl: 'app/views/collectionsLibrary/available.html',
   controller: 'CollectionsLibraryAvailableController',
   ncyBreadcrumb: {
      label: 'Collections Library-Available',
      parent: 'headquarters'
   },
   resolve: {
      controller: function ($q) {
         var deferred = $q.defer();
         require(['controllers/collectionsLibrary/CollectionsLibraryAvailableController'], function () {
            deferred.resolve();
         });
         return deferred.promise;
      }
   }
})

.state('collectionsLibrary.my', {
   url: 'my/',
   templateUrl: 'app/views/collectionsLibrary/my.html',
   controller: 'CollectionsLibraryMyController',
   ncyBreadcrumb: {
      label: 'Collections Library-My',
      parent: 'headquarters'
   },
   resolve: {
      controller: function ($q) {
         var deferred = $q.defer();
         require(['controllers/collectionsLibrary/CollectionsLibraryMyController'], function () {
            deferred.resolve();
         });
         return deferred.promise;
      }
   }
})

.state('collectionsWorkPage', {
   url: '/headquarters/collections-library/:id/edit/',
   templateUrl: 'app/views/collectionsWorkPage.html',
   controller: 'CollectionsWorkPageController',
   ncyBreadcrumb: {
      label: 'Edit Collection',
      parent: 'collectionsLibrary.available'
   },
   params: {
      data: {}
   },
   resolve: {
      controller: function ($q, $stateParams) {
         var deferred = $q.defer($stateParams);
         require(['controllers/CollectionsWorkPageController'], function () {
            deferred.resolve();
         });
         return deferred.promise;
      }
   }
})

回答1:


app.config(['$breadcrumbProvider', configNcyBreadcrumb])

function configNcyBreadcrumb($breadcrumbProvider) {
    $breadcrumbProvider.setOptions({
        includeAbstract : true
    });
}



回答2:


The parent property can be either a string or a function returning the parent name. The function provides the scope of the current state controller (the same used for labels interpolation).

So you can do something like this:

ncyBreadcrumb: {
  label: 'Edit Collection',
  parent: function($scope) {
    if($scope.tab === 'MY') // Constant defined in CollectionsLibraryMyController
      return 'collectionsLibrary.my';
    else if($scope.tab === 'AVAILABLE') // Constant defined in CollectionsLibraryAvailableController
      return 'collectionsLibrary.available';
  }
}

See API reference for more details



来源:https://stackoverflow.com/questions/30905511/how-to-use-ncy-breadcrumb-in-child-state-of-abstract-parent

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!