Sunday, May 12, 2024
 Popular · Latest · Hot · Upcoming
95
rated 0 times [  98] [ 3]  / answers: 1 / hits: 35760  / 8 Years ago, wed, march 9, 2016, 12:00:00

This is my code



$http.get(/Student/GetStudentById?studentId= + $scope.studentId + &collegeId= + $scope.collegeId)
.then(function (result) {
});


In the above code use http service for get student details based on id. but i want to write the above service string.format like in c#.net



(eg:- string.format(/Student/GetStudentById/{0}/collegeId/{1},studentId,collegeId)

More From » angularjs

 Answers
14
   String.format = function () {
// The string containing the format items (e.g. {0})
// will and always has to be the first argument.
var theString = arguments[0];

// start with the second argument (i = 1)
for (var i = 1; i < arguments.length; i++) {
// gm = RegEx options for Global search (more than one instance)
// and for Multiline search
var regEx = new RegExp(\{ + (i - 1) + \}, gm);
theString = theString.replace(regEx, arguments[i]);
}

return theString;
}

$http.get(String.format(/Student/GetStudentById?studentId={0}&collegeId={1}, $scope.studentId , $scope.collegeId))
.then(function (result) {
});

[#63006] Sunday, March 6, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
emiliano

Total Points: 381
Total Questions: 109
Total Answers: 93

Location: Jersey
Member since Fri, Oct 1, 2021
3 Years ago
emiliano questions
;