Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/372.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 解决在Angular ui路由器中不工作的问题_Javascript_Angularjs_Angular Ui Router - Fatal编程技术网

Javascript 解决在Angular ui路由器中不工作的问题

Javascript 解决在Angular ui路由器中不工作的问题,javascript,angularjs,angular-ui-router,Javascript,Angularjs,Angular Ui Router,我试图使用解析从我的控制器(Rates Controller)中的Rates服务预先加载数据,并获得一个空白屏幕。api可以工作,但由于某种原因,当我一步一步地执行时,它跳过了服务中的$http.get方法:-/。有人对如何解决这个问题有什么建议吗?干杯 rates.contoller.js (function () { 'use strict'; angular.module('print.module').controller('ratesCtrl', ['ratesTest123', f

我试图使用解析从我的控制器(Rates Controller)中的Rates服务预先加载数据,并获得一个空白屏幕。api可以工作,但由于某种原因,当我一步一步地执行时,它跳过了服务中的$http.get方法:-/。有人对如何解决这个问题有什么建议吗?干杯

rates.contoller.js

(function () {
'use strict';

angular.module('print.module').controller('ratesCtrl', ['ratesTest123', function (ratesTest123) {
    console.log(ratesTest123);
}]
)})();
(function () {
'use strict';

angular.module('print.module').service('ratesService', ['$http', function ($http) {
    vm = this;

    function getRatesDataService() {
        console.log("test");
        return this.$http.get("api/Rates/GetRates");
    }

    //}
}]
)
})();
(function () {
"use strict";

var module = angular.module('print.module', [
    'ui.router',
]);
module.config(function ($stateProvider, $urlRouterProvider, $locationProvider) {
    $urlRouterProvider.otherwise('/print');
    $stateProvider
        .state('print', {
            url: '/print',
            templateUrl: "Public/scripts/sharedViews/printNavbar.html"

        })
        .state('print.rates', {
            url: "/rates",
            controller: 'ratesCtrl',
            templateUrl: "Public/scripts/rates/rates.view.html",
            controllerAs: 'vm',
            resolve: {
                    ratesTest123: ['ratesService', '$q', function (ratesService, $q) {
                        var deferred = $q.defer();
                        ratesService.getRatesDataService().then(function (response) {
                            deferred.resolve(response.data);
                        });
                        return deferred.promise;
                     }]
                }
        })

   $locationProvider.html5Mode(true);
});

}());
rates.service.js

(function () {
'use strict';

angular.module('print.module').controller('ratesCtrl', ['ratesTest123', function (ratesTest123) {
    console.log(ratesTest123);
}]
)})();
(function () {
'use strict';

angular.module('print.module').service('ratesService', ['$http', function ($http) {
    vm = this;

    function getRatesDataService() {
        console.log("test");
        return this.$http.get("api/Rates/GetRates");
    }

    //}
}]
)
})();
(function () {
"use strict";

var module = angular.module('print.module', [
    'ui.router',
]);
module.config(function ($stateProvider, $urlRouterProvider, $locationProvider) {
    $urlRouterProvider.otherwise('/print');
    $stateProvider
        .state('print', {
            url: '/print',
            templateUrl: "Public/scripts/sharedViews/printNavbar.html"

        })
        .state('print.rates', {
            url: "/rates",
            controller: 'ratesCtrl',
            templateUrl: "Public/scripts/rates/rates.view.html",
            controllerAs: 'vm',
            resolve: {
                    ratesTest123: ['ratesService', '$q', function (ratesService, $q) {
                        var deferred = $q.defer();
                        ratesService.getRatesDataService().then(function (response) {
                            deferred.resolve(response.data);
                        });
                        return deferred.promise;
                     }]
                }
        })

   $locationProvider.html5Mode(true);
});

}());
print.module.js

(function () {
'use strict';

angular.module('print.module').controller('ratesCtrl', ['ratesTest123', function (ratesTest123) {
    console.log(ratesTest123);
}]
)})();
(function () {
'use strict';

angular.module('print.module').service('ratesService', ['$http', function ($http) {
    vm = this;

    function getRatesDataService() {
        console.log("test");
        return this.$http.get("api/Rates/GetRates");
    }

    //}
}]
)
})();
(function () {
"use strict";

var module = angular.module('print.module', [
    'ui.router',
]);
module.config(function ($stateProvider, $urlRouterProvider, $locationProvider) {
    $urlRouterProvider.otherwise('/print');
    $stateProvider
        .state('print', {
            url: '/print',
            templateUrl: "Public/scripts/sharedViews/printNavbar.html"

        })
        .state('print.rates', {
            url: "/rates",
            controller: 'ratesCtrl',
            templateUrl: "Public/scripts/rates/rates.view.html",
            controllerAs: 'vm',
            resolve: {
                    ratesTest123: ['ratesService', '$q', function (ratesService, $q) {
                        var deferred = $q.defer();
                        ratesService.getRatesDataService().then(function (response) {
                            deferred.resolve(response.data);
                        });
                        return deferred.promise;
                     }]
                }
        })

   $locationProvider.html5Mode(true);
});

}());
查看(脚本标签仅供参考)


将getRatesDataService功能分配给您的服务

(function () {
 'use strict';

 angular.module('print.module').service('ratesService', ['$http', function ($http) {

    this.getRatesDataService = function () {
       console.log("test");
       return $http.get("api/Rates/GetRates");
    }

   //}
}]
)
} )();
由于它返回一个承诺,您可以简单地执行以下操作

    resolve: {
                ratesTest123: ['ratesService',  function (ratesService) {
                    return ratesService.getRatesDataService()
                 }]
            }