angular-breadcrumb
angular-breadcrumb copied to clipboard
Breadcrumbs not working in directive
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
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) ?
I can reproduce this. Check this plunker.
I think you register the $viewContentLoaded event in here too late, when the controller is already executed.
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?
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.