Skip to content

How i can get current state name in templateProvider #1898

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

Closed
Claud opened this issue Apr 20, 2015 · 9 comments
Closed

How i can get current state name in templateProvider #1898

Claud opened this issue Apr 20, 2015 · 9 comments

Comments

@Claud
Copy link

Claud commented Apr 20, 2015

.state('ap.articles.create', {
            url: '/create',
            controller: CreateCtrl,
            controllerAs: 'PageCtrl',
            templateProvider: function ($state, $http, $templateCache) {
                console.log($state.current);
                return getTemplate($state.current.name, $state, $http, $templateCache);
            },

Output log()

Object {name: "", url: "^", views: null, abstract: true}
@nateabele
Copy link
Contributor

Unfortunately this is not yet supported, however it will be shortly.

Your best bet in the meantime is to create a factory function into which you pass the state name, i.e.:

{
  // ...
  templateProvider: templateProviderFactory("ap.articles.create");
}

function templateProviderFactory(stateName) {
  return function function ($state, $http, $templateCache) {
    console.log(state);
    return getTemplate(state, $state, $http, $templateCache);
   };
}

Requires a little duplication, but should work until this is fully supported.

@ivan-zakharchuk
Copy link

@robstoll
Copy link

+1
This feature would also simplify some of my code

@anton-isaykin
Copy link

+1

@stale
Copy link

stale bot commented Jan 24, 2020

This issue has been automatically marked as stale because it has not had
recent activity. It will be closed if no further activity occurs.

This does not mean that the issue is invalid. Valid issues
may be reopened.

Thank you for your contributions.

@stale stale bot added the stale label Jan 24, 2020
@robstoll
Copy link

Please re-investegate

@stale stale bot removed the stale label Jan 24, 2020
@stale
Copy link

stale bot commented Jul 25, 2020

This issue has been automatically marked as stale because it has not had
recent activity. It will be closed if no further activity occurs.

This does not mean that the issue is invalid. Valid issues
may be reopened.

Thank you for your contributions.

@stale stale bot added the stale label Jul 25, 2020
@stale stale bot closed this as completed Aug 8, 2020
@neilmaledev
Copy link

Is this now supported?

@marvinking
Copy link

marvinking commented Jun 9, 2022 via email

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

No branches or pull requests

7 participants