0

I have a router configured like this:

.state('home.view-profile', {
    url: '/view-profile/:profileUrl',
    template: '<view-profile input="$resolve.profileData"></view-profile>',
    title: 'View Profile',
    resolve: {profileData: function(artistService, $stateParams){
      return artistService.getArtist($stateParams.profileUrl).then((data) => {
        const timer = new Date();
        console.log(timer.getSeconds() + ':' + timer.getMilliseconds());
        console.log(data.data.artist);
        return data.data.artist;
      });
    }
  }
  })

and the component

module.component('view-profile', {
templateUrl: 'view-profile/view-profile.component.html',
    bindings: {
      input: '='
    },
    controller: ['$state', '$scope', '$stateParams', function ($state, $scope, $stateParams) {
      const model = this;
      console.log('***************');
      console.log(model.input);
   }]
});

I could see that data.data.artist is valid and accessible from the log during resolving process, but inside the component the input is always undefined J just don't understand why is this happening?

2
  • maybe you should inject $resolve to your controller Commented Aug 29, 2016 at 0:05
  • I tried, but it has no any meaningfull data on it.. Commented Aug 29, 2016 at 11:05

2 Answers 2

1

sorry and thanks for your help! I just found out out the issue. The version of the ui-router was downgraded somehow during our multi-devs workflow. Some of the developers installed 0.2.1 instead of the latest 0.3.x, i merged and that was the problem. Only 0.3.x router supports sending $resolve.param to component bindings.
After upgrading - everything works fine. Only my self-confidence is harmed...

Sign up to request clarification or add additional context in comments.

Comments

0

Have you tried resolving the promise in the controller?

model.input.then(function(res) { console.log(res); }

3 Comments

nope, that didnt work... cannot find provider profileData
Duh. I was too quick and didn't look through your code well enough to see you were passing things around. Try resolving the promise in the controller to see if that works.
I could, but as model.input is 'undefined', and I'm sure about it, it will through an error...

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.