Angularjs 将服务传递给ui路由器';s决心避免发出$http请求
我越来越熟悉ui路由器和使用。然后与。成功相反。然而,我在通过一项服务时遇到了一些困难。目前,resolve正在阻止对控制器的访问。我的目标是在每个用户被选中时从他们那里获取个人信息 我通过ui路由器wiki引用了解析。翻译2似乎与我使用服务的方式相似 我在resolve的customerId中引用服务调用,这是我传递给ordersController的内容 这是我为顾客提供的服务Angularjs 将服务传递给ui路由器';s决心避免发出$http请求,angularjs,angular-ui-router,resolve,Angularjs,Angular Ui Router,Resolve,我越来越熟悉ui路由器和使用。然后与。成功相反。然而,我在通过一项服务时遇到了一些困难。目前,resolve正在阻止对控制器的访问。我的目标是在每个用户被选中时从他们那里获取个人信息 我通过ui路由器wiki引用了解析。翻译2似乎与我使用服务的方式相似 我在resolve的customerId中引用服务调用,这是我传递给ordersController的内容 这是我为顾客提供的服务 (function() { angular .module('app.servic
(function() {
angular
.module('app.services',[])
.factory('customersFactory', customersFactory);
function customersFactory($http, $log, $q) {
return {
getCustomers: getCustomers
};
function getCustomers(){
var defer = $q.defer();
return $http.get('./Services/customers.json',{catch: true})
.then(getCustomerListComplete)
.catch(getCustomerListFailed);
function getCustomerListComplete(response) {
console.log('response.data',response.data);
// defer.resolve(response.data);
return response.data;
}
function getCustomerListFailed(error) {
console.log('error', error);
}
}
}
}());
这是我的控制器。就目前而言,它相当小。我希望先访问它。不过,我确实向它注入了customerId
(function() {
// 'use strict';
angular
.module('app.orders')
.controller('OrdersController', OrdersController);
function OrdersController($stateParams, customerId) {
console.log(customerId);
var vm = this;
vm.title = "Customer Orders";
vm.customer = null;
}
}());
*******更新*****
我发现我在使用ng Route时查看了一些代码。
在这里,我使用$route的方式与我希望使用$stateParams的方式相同
resolve: {
cityDetails:['cacFindCountry','$route', function(cacFindCountry,$route){
var countryCode = $route.current.params.countryCode;
console.log('cityDetails',cacFindCountry(countryCode))
return cacFindCountry(countryCode);
}],
countryNeighbors : ['cacFindNeighbors','$route', function(cacFindNeighbors,$route) {
var countryCode = $route.current.params.countryCode;
// pushes country code into neighbors
return cacFindNeighbors(countryCode);
}],
countryDetails : ['cacCountries', '$route', function(cacCountries, $route) {
var countryCode = $route.current.params.countryCode;
console.log(countryCode);
console.log(cacCountries(countryCode));
// need to get specific country info
// return cacCountries(countryCode);
return countryCode;
}]
}
resolve: {
cityDetails:['cacFindCountry','$route', function(cacFindCountry,$route){
var countryCode = $route.current.params.countryCode;
console.log('cityDetails',cacFindCountry(countryCode))
return cacFindCountry(countryCode);
}],
countryNeighbors : ['cacFindNeighbors','$route', function(cacFindNeighbors,$route) {
var countryCode = $route.current.params.countryCode;
// pushes country code into neighbors
return cacFindNeighbors(countryCode);
}],
countryDetails : ['cacCountries', '$route', function(cacCountries, $route) {
var countryCode = $route.current.params.countryCode;
console.log(countryCode);
console.log(cacCountries(countryCode));
// need to get specific country info
// return cacCountries(countryCode);
return countryCode;
}]
}