How to Write string format in angularjs like as c#?
This question already has an answer here:
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) {
});
尝试这个,
String.format = function(str) {
var args = arguments;
return str.replace(/{[0-9]}/g, (matched) => args[parseInt(matched.replace(/[{}]/g, ''))+1]);
};
string.format("/Student/GetStudentById/{0}/collegeId/{1}",studentId,collegeId)
you can use sprintf() of javascript.
please take a look at sprintf()
链接地址: http://www.djcxy.com/p/90578.html上一篇: 从依赖关系jar中排除资源