dealing with trailing slashes in angularjs -
i have function looks this:
$scope.deletetodo = function(id) { var url = '/musicians/' + id; console.log("url" + url); $http.delete(url, { 'id': id}) .success(function(data) { $scope.todos = data; console.log(data); }) .error(function(data) { console.log('error: ' + data); }); };
if id 123, /musicians123
however, expecting /musicians/123
.
i straightaway error , not print console.log
statement. since it before $http.delete, believe should have been printed not.
i have tried escaping /
using \\/
did not help.
also, tried configure with:
.config(['$resourceprovider', function($resourceprovider) { // don't strip trailing slashes calculated urls $resourceprovider.defaults.striptrailingslashes = false; }]);
stacktrace:
delete http://localhost:3000/musicians55accbce27e2cd2802de4894 404 (not found)$get.id @ angular.min.js:100n @ angular.min.js:96l @ angular.min.js:95$get.l.(anonymous function) @ angular.min.js:97$scope.deletetodo @ vm416 core.js:43w @ angular.min.js:73(anonymous function) @ angular.min.js:145$get.e.$eval @ angular.min.js:89$get.e.$apply @ angular.min.js:89(anonymous function) @ angular.min.js:145x.event.dispatch @ jquery.min.js:5x.event.add.y.handle @ jquery.min.js:5 vm416 core.js:49 error: error: not found @ layer.handle (c:\users\dev4\desktop\sample\server.js:86:13) @ trim_prefix (c:\users\dev4\desktop\sample\node_modules\express\lib\router\index.js:226:17) @ c:\users\dev4\desktop\sample\node_modules\express\lib\router\index.js:198:9 @ function.proto.process_params (c:\users\dev4\desktop\sample\node_modules\express\lib\router\index.js:251:12) @ next (c:\users\dev4\desktop\sample\node_modules\express\lib\router\index.js:189:19) @ next (c:\users\dev4\desktop\sample\node_modules\express\lib\router\index.js:166:38) @ next (c:\users\dev4\desktop\sample\node_modules\express\lib\router\index.js:166:38) @ next (c:\users\dev4\desktop\sample\node_modules\express\lib\router\index.js:166:38) @ next (c:\users\dev4\desktop\sample\node_modules\express\lib\router\index.js:166:38) @ next (c:\users\dev4\desktop\sample\node_modules\express\lib\router\index.js:166:38) @ next (c:\users\dev4\desktop\sample\node_modules\express\lib\router\index.js:166:38) @ next (c:\users\dev4\desktop\sample\node_modules\express\lib\router\index.js:166:38) @ next (c:\users\dev4\desktop\sample\node_modules\express\lib\router\index.js:166:38) @ next (c:\users\dev4\desktop\sample\node_modules\express\lib\router\index.js:166:38) @ next (c:\users\dev4\desktop\sample\node_modules\express\lib\router\index.js:166:38) @ next (c:\users\dev4\desktop\sample\node_modules\express\lib\router\index.js:166:38
but no help. how fix this?
there nothing wrong posted. additionally, resourceprovider has nothing how slashes parsed in string. working example, see http://plnkr.co/edit/y99e2pqa6rfvrkg1t6zz?p=preview .
angular.module('app', []) .controller('testctrl', ['$scope', function($scope) { $scope.demo = function(id) { var url = '/base/' + id; alert("url: " + url); //it gives `base123` if 123 id }; }]); <!doctype html> <html ng-app="app"> <head> <script data-require="angular.js@1.4.3" data-semver="1.4.3" src="https://code.angularjs.org/1.4.3/angular.js"></script> <script src="script.js"></script> </head> <body ng-controller="testctrl"> <a href="" ng-click="demo('123')">test demo function</a> </body> </html>
Comments
Post a Comment