B
B
Bogdan Bembenok2016-01-28 04:56:59
JavaScript
Bogdan Bembenok, 2016-01-28 04:56:59

How to get data from resolve in TemplateProvider?

The essence of the gap is as follows:
you need to get the object from resolve, and check its role, if the role is "x" give the template "x" if "y" - in turn, the template "y" ..
State receives resolve only after the template is loaded. What are the solutions?
I will be grateful

.state('person', {
      abstract: true,
      url: "/id{id}",
      views: {
        'header': {
          templateUrl: "modules/authorization/header_view.html",
          controller: "authorizationCtrl",
          resolve: {
            authorizationService: 'authorizationService'
          }
        },
        'content': {
          templateProvider: ['$stateParams', 'personService', function($stateParams, personService) {
            return 'modules/person/lawyer_view.html';
          }],
          controller: "personCtrl",
          resolve: {
            personService: 'personService',
            profile: ['$stateParams', 'personService', function($stateParams, personService) {
              var userId = $stateParams.id;
              console.log('second');
              return personService.getUser(userId);
            }]
          }
        }
      }
    })

Answer the question

In order to leave comments, you need to log in

1 answer(s)
_
_ _, 2016-01-28
@AMar4enko

Recent versions of ui-router support locals from the resolve section in templateProvider.
Check your version and try to do

templateProvider: ['$stateParams', 'profile', function($stateParams, profile) {
            return 'modules/person/lawyer_view.html';
          }],

As far as I remember, templateProvider returns the template data itself, not the url (or the promise that will return the data). You can use $templateRequest to pull data from template url, it uses $templateCache inside.
PS https://github.com/angular-ui/ui-router/releases/t...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question