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

Breadcrumbs not working in directive

Open bautistaaa opened this issue 10 years ago • 4 comments

This may just be a scoping issue but was hoping you had a work around.

Below is my state

    .state('home.metric', {
    url: '/Metric/:metricId'
    controller: 'MyCtrl'
    ncyBreadcrumb: {
        label: '{{getLabel($stateParams.metricId)}}'
    }

Controller:

       .controller('MyCtrl', function($scope) {
               $scope.getLabel = function(id) {
                      return getName(id);
               }
        }

I have a directive with isolated scope that uses ncy-breadcrumb but it can't see the getLabel method in the controller. However, if i back out that state and go back the breadcrumb will show. Not sure if you have any idea how I can get around this.

initial visit console.log(step)

Object {url: "/Metric/:metricId", resolve: Object, views: Object, ncyBreadcrumb: Object, name: "home.metric"…}$$hashKey: "00L"
name: "home.metric"
ncyBreadcrumb: 
**ObjectncyBreadcrumbLabel: ""**
ncyBreadcrumbLink: "#/Home/Metric/13"resolve: 
Objecturl: "/Metric/:metricId"views: Object__proto__: Object

if i hit back and revisit the same link you'll see that the label is now populated.

Object {url: "/Metric/:metricId", resolve: Object, views: Object, ncyBreadcrumb: Object, name: "home.metric"…}$$hashKey: "00L
"name: "home.metric"
**ncyBreadcrumb: ObjectncyBreadcrumbLabel: "Key Task Processes"**
ncyBreadcrumbLink: "#/Home/Metric/13"
resolve: 
Objecturl: "/Metric/:metricId"views: Object__proto__: Object

bautistaaa avatar Apr 06 '15 20:04 bautistaaa

Hi,

I can't see why the getLabel is unknown at first.

At first sight, the directive with isolated scope has nothing to do with the problem because labels are evaluated against the controller's scope and I use the event system to get it.

Please can you try to reproduce the bug in a plunker (you can fork this one) ?

ncuillery avatar May 16 '15 14:05 ncuillery

I can reproduce this. Check this plunker.

I think you register the $viewContentLoaded event in here too late, when the controller is already executed.

faridnsh avatar Jun 04 '15 19:06 faridnsh

I'm hitting exactly the same problem. When displaying a page for the first time the events don't fire (presumably because they're registered too late indeed as the directive is processed), but if you navigate back and again it works.

I noticed that because of grunt serve, when it was reloading by browser the breadcrumb was missing entries where the label is read from the scope.

Any idea how that could be fixed?

nguillaumin avatar Aug 25 '15 06:08 nguillaumin

Hey guys, I faced with the same situation and all I had to do it's just inject $breadcrumb to my directive. Check this plunker.

viktorhunko avatar Mar 02 '16 17:03 viktorhunko