You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
Since Angular 1.4.9, the $http service only accepts pure strings as URLs. If I pass in an object that has a toString() method, $http raises an exception:
varurl={toString: function(){return'http://www.example.com';}};$http.get(url);// Throws "Error: [$http:badreq] Http request configuration url must be a string."
This is a departure from Angular's pre-1.4.9 behavior, jQuery, and XMLHttpRequest; all of which accept (and correctly interpret) the url object described above. This behavior was introduced in 6628b4f to fix #12925, and merged in #13444.
I would recommend relaxing this restriction slightly, and allow objects with a toString() method to be used as URLs.
The relevant portion of $http's source currently looks like:
if(!isString(requestConfig.url)){throwminErr('$http')('badreq','Http request configuration url must be a string. Received: {0}',requestConfig.url);}
I would recommend changing it to something like this:
varisStringlike=function(val){returnisString(val)||(isObject(val)&&isFunction(val.toString));};if(!isStringlike(requestConfig.url)){throwminErr('$http')('badreq','Http request configuration url must be a string. Received: {0}',requestConfig.url);}
While this would result in a less-satisfactory fix for #12925 (we might throw a less descriptive error in some cases), the behavior would also be more correct.