[英]Send a list of parameters in angular and change route
I trying to call other route in angular, similar this 我试图用角形调用其他路线,类似
$location.path($scope.productPath+"/approveProducts/").search({ids}); 。$ location.path($ scope.productPath + “/ approveProducts /”)搜索({IDS});
I want send the list of ids to other controller but the ids are sending by url 我想将ID列表发送到其他控制器,但是ID是通过url发送的
http://localhost:8080/#/product?ids=1130&ids=1132&ids=7428&ids=15574&ids=15579&ids=15580&ids=6798968768697789 HTTP://本地主机:8080 /#/产品ID = 1130&IDS = 1132&IDS = 7428&IDS = 15574&IDS = 15579&IDS = 15580&IDS = 6798968768697789
I need send ids similar a post requisition, not in a url, because i have a many ids in my call 我需要发送类似请求后的ID,而不是发送URL,因为我的通话中有很多ID
How i do this in angular, send parameters and change my route to other controller? 我该如何做角度,发送参数并更改到其他控制器的路线?
I believe a better approach might be to utilize the angularjs service/factory to persist your data. 我相信更好的方法可能是利用angularjs服务/工厂来持久化数据。
example: 例:
.service('AngularJsService', function() {
var listOfIds = [];
return {
saveData: function(theIdsToSave) {
listOfIds = theIdsToSave;
},
getData: function () {
return listOfIds;
}
}
}
.controller('OriginatingController', function($location, AngularJsService) {
function navigateToTargetController() {
AngularJsService.saveData([1,2,3,4]);
$location.path('pathToTargetController');
}
}
.controller('TargetController', function($location, AngularJsService) {
function retrieveData() {
var ids = AngularJsService.getData();
// ids = [1,2,3,4]
}
}
You can use $http
for send your params and then change your route 您可以使用
$http
发送参数,然后更改路线
var req = {
method: 'POST',
url: 'http://example.com',// address for sending ids
headers: {
'Content-Type': undefined
},
data: { test: 'test' }
}
$http(req).then(function(){
// this you can to change your url
$location.path($scope.productPath+"/approveProducts/");
}, function(){...});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.