I am new to Angular, and am having an issue where my $http url placeholders are not being replaced by the actual data. What I want is for this:
"/json/:searchType/:userId"
To be replaced with this when I use my $http call:
"/json/user/123"
Instead, I get something like this, according to firebug's Net tab:
"/json/:searchType/:userId?userId=123&searchType=user"
I have tried to create a fiddle, but because I use different views and json data from a server, I'm not sure how to create something that works in the fiddle that still looks anything like what I am actually doing. I have looked at this answer, this answer, this answer, this answer, and this answer, to name a few. I'm having trouble finding a posting that isn't about $resource, or the @ notation it uses to link url params to object params though.
To explain, I'm using a service to pass the searchType and accountId params between controllers and my factory, which actually performs the $http request.
Here is my controller:
.controller('UserDetailsCtrl', ["$scope", "Search", function ($scope, Search) {
$scope.result = Search.getUser();
}])
Here is my Factory:
.factory('Search', ["$http", "SearchCriteriaSvc", function($http, SearchCriteriaSvc) {
var baseUrl = "/json/:searchType/:accountId";
return {
getUser: function () {
return $http.get(baseUrl,
{params:
{
accountId: SearchCriteriaSvc.getAccountId(),
searchType: SearchCriteriaSvc.getSearchType()
}
})
.then(function(result) {
return result.data;
});
}
}
}])
Finally, my service:
.service('SearchCriteriaSvc', function() {
var searchType = "",
userId = "";
return {
getSearchType: function () {
return searchType;
},
setSearchType: function(value) {
searchType = value;
},
getUserId: function () {
return userId;
},
setUserId: function(value) {
userId= value;
}
};
})
I have tried not using the service to pass the params (just manually typing in strings) and I get the same result, so I don't think that my service is the issue, but then, I'm at a loss.
Any help would be great. Thanks!