angularjs resolve未定义

时间:2017-11-20 00:36:05

标签: angularjs data-binding angular-ui-router

所以在我的州,我有

    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;
                                });
                        }]
                    }
                });
        }]);
然后我得到了正确的回复。但是当我在这里检查我的决心时,

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)

                }

            }]
    });

我发现我的决心是不确定的。我做错了吗?

1 个答案:

答案 0 :(得分:1)

$stateProvider会将您在<{1>}对象内部指定的内容绑定到组件,而不是绑定整个resolve对象本身。

resolve

文档链接:https://ui-router.github.io/ng1/docs/latest/interfaces/state.statedeclaration.html#as-an-object