i need to use js code in about 10 pages - but each page will have get url not as other as example:
page 1: will use get url: /api/Ready
page 2: will use get url: /api/NotReady
page 3: will use get url: /api/Done
page 4: will use get url: /api/waiting list
all will use that same js code:
var app = angular.module('jqanim', []);
app.controller('InvoiceController', [
'$scope', '$http', function ($scope, $http) {
$http.get("/api/NoReady") // this is url needed to pass as parameter ?
.success(function (data) {
var dataByMonth = {};
data.forEach(itemToMonth);
$scope.customersByMonth = dataByMonth;
function itemToMonth(item) {
item.MirageDate = new Date(item.MirageDate)
var month = item.MirageDate.getMonth();
var year = item.MirageDate.getFullYear();
dataByMonth[year + '-' + month] = dataByMonth[year + '-' + month] || [];
dataByMonth[year + '-' + month].push(item);
}
});
}
]);
so please can i get help about that with sample example to learn how can i do it ?
Thanks a lot ...
postapigeturlAngularJS
__________________
Best Regards
Eng.Ahmed Amin
ahmed.mo.amin@gmail.com
You can create a global array which will hold all these urls. and then pass the index as urlid in the parameter.
//globalarray. var array = ['/api/Ready', '/api/NotReady', '/api/Done', '/api/waiting list'] //function to get parameter by name
function getParameterByName(name) {
name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
results = regex.exec(location.search);
return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}
var url = array[parseInt(getParameterByName('urlid'))];
alert(url);
Now you can pass the index in the url as suppose your page 1 needs to use ready call then
http://localhost/Home/Page1?urlid=0 you can passit like this.
then put url variable in the $http.get
$http.get(url) // this is url needed to pass as parameter ?
Hope this helps.
With Regards,
Krunal Parekh
Krunal
MSDN Community Support
Please remember to "Mark as Answer" the responses that resolved your issue.
Member
51 Points
449 Posts
Angularjs - How can i pass get or post url as a parameter ?
Jun 30, 2015 05:34 AM|a.amin|LINK
Hi
i need to use js code in about 10 pages - but each page will have get url not as other as example:
all will use that same js code:
so please can i get help about that with sample example to learn how can i do it ?
Thanks a lot ...
post api get url AngularJS
Best Regards
Eng.Ahmed Amin
ahmed.mo.amin@gmail.com
All-Star
15252 Points
2074 Posts
Re: Angularjs - How can i pass get or post url as a parameter ?
Jul 01, 2015 02:43 AM|Krunal Parekh|LINK
Hello a.amin,
You can create a global array which will hold all these urls. and then pass the index as urlid in the parameter.
Now you can pass the index in the url as suppose your page 1 needs to use ready call then http://localhost/Home/Page1?urlid=0 you can passit like this.
then put url variable in the $http.get
Hope this helps.
With Regards,
Krunal Parekh
MSDN Community Support
Please remember to "Mark as Answer" the responses that resolved your issue.