Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

label function support #63

Open
dotnetwise opened this issue Dec 11, 2014 · 15 comments
Open

label function support #63

dotnetwise opened this issue Dec 11, 2014 · 15 comments

Comments

@dotnetwise
Copy link

It should work exactly the same way as parent

@ncuillery
Copy link
Owner

Have you faced a situation where you could have need this feature?

I ask myself if this feature could be useful because the label can already be a expression calling a function in the scope:

// config
$stateProvider.state('main', {
  [...],
  ncyBreadcrumb: {
    label: '{{getBreadcrumbLabel()}}'
  }
})

// controller
$scope.getBreadcrumbLabel = function() {
  // Something with scope here
}

Anyway, thanks for the suggestion.

@dotnetwise
Copy link
Author

Yes, when having multiple views it binds to every scope of every view, which is wrong.
Besides the logic of The breadcrumb should be in the provider config not in the scope

-----Original Message-----
From: "Nicolas Cuillery" [email protected]
Sent: ‎14/‎12/‎2014 06:20 PM
To: "ncuillery/angular-breadcrumb" [email protected]
Cc: "dotnetwise" [email protected]
Subject: Re: [angular-breadcrumb] label function support (#63)

Have you faced a situation where you could have need this feature?
I ask myself if this feature could be useful because the label can already be a expression calling a function in the scope:
// config
$stateProvider.state('main', {
[...],
ncyBreadcrumb: {
label: '{{getBreadcrumbLabel()}}'
}
})

// controller
$scope.getBreadcrumbLabel = function() {
// Something with scope here
}Anyway, thanks for the suggestion.

Reply to this email directly or view it on GitHub.=

@ncuillery ncuillery removed the waiting label Dec 16, 2014
@ncuillery
Copy link
Owner

OK, it could be a nice feature for v0.4.x

@ghost
Copy link

ghost commented Jan 9, 2015

Hi,

I was wondering the same thing. And I tried what you suggested @ncuillery, passing a scope function to the label, but it doesn't display what I return.

Here's a quick example, maybe I'm doing something wrong: http://plnkr.co/edit/Uj8RTNqbPNKx9q9cHohp

Thanks for looking into it.

@ghost
Copy link

ghost commented Jan 9, 2015

Ok, after a bit of search, I'm logging line 211, parseLabel(viewScope), and that runs a few times (more and more times each time I visit the page without reloading if that makes sense...), and on some runs, I get the result from my function but at the end run I do not. So I don't understand.

It goes like so:
Home
Forums:
Home
Forums: myForum
Home
Forums:
Home
Forums:

So I guess that because the last run gives an empty response, that's why my code isn't showing. But don't know why...

@sturay
Copy link

sturay commented Feb 20, 2015

It is perhaps worth noting that using the above approach, I was only able to output the function after injecting $rootScope into the controller. So,

// controller
$scope.getBreadcrumbLabel = function() {
  // Something with scope here
}

would become:

// controller
$rootScope.getBreadcrumbLabel = function() {
  return $scope.parent.child;
}

@fgarit
Copy link

fgarit commented Mar 19, 2015

I would also see the use for having a function for label.
function($scope, $state)
Maybe the function could return a promise that would be waited on before displaying.

Basically, I've got states that have have a parent state with a dynamic label.
And I would like for there to be a way to handle that.

Home > user name > current state

"user name" would be a state such as "site.user({id: 12})", and I would like in the label function to be able to perform a backend query to get the name of the user and output it there.

While it's true the backend query can be done in the current state and some scope var can be set to print the user name, I would prefer if the current state didn't have to handle that. I would like each state to handle its own labeling.

@fgarit
Copy link

fgarit commented Mar 19, 2015

I guess ideally, I would like to have a breadCrumb builder like:

.state('site.users', {
  url: '/users/{id:[0-9]+}',
  templateUrl: 'users.html',
  controller: 'UsersController',
  ncyBreadcrumb: {
        builder: function($injector, $state) {
            var someService = $injector.get('someService');
            var $q = $injector.get('$q');
            var deferred = $q.defer();
            someService($state.params.id).then(function(result) {
              deferred.resolve({ label : result.label, parent : result.parent });
            }
            return deferred.promise;
        }
  }
})

In the meantime, I've been thinking of using the getStatesChain function and at each state update, run some function on each state to build its label (at least for the states that have a dynamic label).

@bautistaaa
Copy link

this would be helpful, i have multiple controllers using the same state and in order to render their own custom breadcrumbs I have to attach the same function in each controller vs being able to pass in a provider or service

ncyBreadcrumb:{
    label:  function(myService, $stateParams) {
                  return myService.getLabel($stateParams.id);
              }
 }

if there way I can accomplish this?

@shirk3y
Copy link

shirk3y commented Apr 13, 2015

+1

ng-breadcrumbs seems to support it: https://github.com/ianwalter/ng-breadcrumbs#adding-dynamic-route-labels.

@leedavidr
Copy link

+1

@goliney
Copy link

goliney commented Sep 17, 2015

+1 for ability to use $stateParams in label, as @bautistaaa suggested

@inaccessible
Copy link

+1

@ncuillery
Copy link
Owner

Related to #105

@stramel
Copy link

stramel commented Sep 2, 2016

Also related to #146

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants