2

There is code of mine $stateProvider:

$stateProvider
  .state("home", {
      url: "/",
      template: "<employee-info-component user='$resolve.user'></employee-info-component>",
      resolve: {
        user: function(individualFootprintService) {
          var usr = individualFootprintService.getCurrentUser();
          return usr.then(function(data) {
            return data;
          });
        }
      }

It's my service:

function getCurrentUser() {
  return $http
    .get("/user")
    .then(function(response) {
      return response.data;
    });
}

This is my binding in component:

        binding:{
                user: '<'
        }

We tried this controller:

function individualFootprintController(user) {
        var $ctrl = this;
user.then(function (data) {
            $ctrl.user = data;
        });
}

But we are receiving exception Error: [$injector:unpr] Unknown provider: userProvider <- user <- individualFootprintController

And we tried this controller:

function individualFootprintController() {
            var $ctrl = this;
            console.log($ctrl.user);
    }

But user don't comes to the controller and its value is undefined. So my question is how can i get access to the desired object from the controller?

1
  • resolve should directly work on promises, and inject the value resolved (by then) and you should not resolve promise in controller. have you tried removing all the ".then (function )" Commented Dec 1, 2016 at 16:32

1 Answer 1

1

You should use bindings instead of binding.

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.