angular-breadcrumb icon indicating copy to clipboard operation
angular-breadcrumb copied to clipboard

Added support to use ncyBreadcrumb.label as an injector block

Open thebigredgeek opened this issue 8 years ago • 6 comments

This allows more dynamic use of the label. Right now, the label is bound to the parent scope, even if the parent scope is destroyed (such as in the case that the child state is interpolated into the same view as the parent state was contained in). This breaks the breadcrumbs, as the label can no longer interpolate properties from the controller attached to it's state because the controller has been destroyed (as well as the scope).

thebigredgeek avatar Sep 08 '15 22:09 thebigredgeek

Bump?

thebigredgeek avatar Oct 05 '15 17:10 thebigredgeek

Hi,

Apologies for the delay, I'll throw an eye on it soon :angel:

ncuillery avatar Oct 06 '15 10:10 ncuillery

Hi, apologies for the delay since my last apologies :smile:

I think you did a great job here. If I understand well, it can be used by defining ncyBreadcrumb.label as a DI function or array like this:

      .state('room.detail.edit', {
        url: '/edit',
        views: {
          "@" : {
            templateUrl: 'views/room_form.html',
            controller: 'RoomDetailCtrl'
          }
        },
        ncyBreadcrumb: {
          label: function(rooms, $stateParams) {
            for(var index = 0; index < rooms.length; index++) {
              if(rooms[index].roomId === parseInt($stateParams.roomId)) {
                return 'Editing room ' + rooms[index].roomNumber;
              }
            }

            return 'Editing';
          }
        }
      });

It's a flexible way of defining a label and could be a workaround for the problem described here #89, right ?

I have a suggestion: We can easily make the current scope (the one attached to the $viewContentLoaded event, used by all the directives) available for DI by using the third arg locals of $injector.invoke (see docs):

step.ncyBreadcrumbLabel = $injector.invoke(
  step.ncyBreadcrumb.label, 
  undefined, 
  {'$scope': viewScope});

Then you can inject the scope:

        ncyBreadcrumb: {
          label: function($scope, rooms, $stateParams) {
            [...]
          }
        }

It could be useful if other situations, when the current scope hold desired informations. What you think ?

I could be great if we harmonize the syntax with the ncyBreadcrumb.parent where I "inject" the current scope manually here (I can do it later if you prefer, you paved the path here)

ncuillery avatar Dec 23 '15 17:12 ncuillery

Hello, Any idea if this is going to be merged or if there is a workaround ? Thanks

SuPenguin avatar Aug 30 '16 13:08 SuPenguin

Anyone have a status update on this?

stramel avatar Oct 07 '16 15:10 stramel

+1 Would really like this feature.

biltongza avatar Dec 01 '17 07:12 biltongza