1

so in my state, i have

    angular.module('app', ['ui.router', 'chart.js'])
        .config(['$stateProvider', '$urlRouterProvider', function ($stateProvider, $urlRouterProvider) {
            $urlRouterProvider.otherwise('/');
            $stateProvider
                .state('home', {
                    url: '/home',
                    component: 'home',
                    resolve: {
                        data: ['$http', function ($http) {
                            return $http.get('some api call')
                                .then(function (response) {
                                    console.log("this is the response", response);
                                    return response;
                                });
                        }]
                    }
                });
        }]);

then i get the proper response back. but when i check my resolve in here,

angular.module('app')
    .component('home', {
        templateUrl: 'Content/app/components/home.html',
        bindings: {
            resolve: '<'
        },
        controller: [
            function () {
                var vm = this;
                vm.$onInit = function () {
                    console.log("this is the resolve", vm)

                }

            }]
    });

i see that my resolve is undefined. Am i doing something wrong?

1 Answer 1

1

$stateProvider will bind what you specify inside the resolve object to your component, rather than binding the whole resolve object itself.

angular.module('app')
  .component('home', {
    templateUrl: 'Content/app/components/home.html',
    bindings: {
        data: '<'
    },
    controller: [
      function () {
        var vm = this;
        vm.$onInit = function () {
          console.log("this is the resolve", vm)
        }
      }]
  });

Documentation link: https://ui-router.github.io/ng1/docs/latest/interfaces/state.statedeclaration.html#as-an-object

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.