angularjs导航到工厂/服务路由
问题描述:
为什么$ location.url(“/ messages”);不管用? AngularJS中的工厂内的$ location是否有任何限制?任何想法是怎么回事?angularjs导航到工厂/服务路由
如果我做错了什么可以请告诉我应该如何重定向到另一个URL“/ messages”?我无法重新加载页面使用$窗口不是一个选项。
感谢
我厂:
(function() {
'use strict';
angular
.module('app.conversation')
.factory('conversationFactory', conversation);
conversation.$inject = ['$rootScope', '$q', 'authFactory', '$location'];
function conversation($rootScope, $q, authFactory, $location) {
var service = {
changeLocation: changeLocation
};
return service;
function changeLocation() {
$location.url("/messages"); // recarga MIERDA!!!!!
}
}
})();
路线正常工作:
(function() {
'use strict';
angular
.module('app.messages')
.config(configFunction);
configFunction.$inject = ['$routeProvider'];
function configFunction($routeProvider) {
$routeProvider
.when('/messages', {
templateUrl: 'app/messages/messages.html',
controller: 'messagesController',
controllerAs: 'meC',
resolve: {
user: function ($q, $timeout, authFactory) {
return authFactory.isLoggedInPromise();
}
}
}).when('/compose/:to?', {
templateUrl: 'app/messages/compose.html',
controller: 'composeController',
controllerAs: 'mcC',
resolve: {
user: function ($q, $timeout, authFactory) {
return authFactory.isLoggedInPromise();
}
}
});
}
})();
答
使用$location.path("/messages");
答
我所做的:
$ location.path(“/消息“); //然后 $ rootScope。$适用()
除非我很困惑,你不使用'角度-UI-router'(第三方库)所有,而是内置角度路由器。我几乎发布了一个ui路由器的具体答案('$ state.go(...)'),然后才意识到这一点... –
我继续编辑它为你';-) –
退房: http:// *.com/questions/19499323/location-path-doesnt-change-in-a-factory-with-angularjs –