Reputation: 39
I have an angular controller whereby I'm trying to look through a list of strings, querying an ajax query for each string within the list. The code is as follows:
var itemsliststrings = ["department", "year", "project", "subdepartment"];
itemsliststrings.forEach(function (itemStr) {
$http.post("/Budget/GetListBudget", { budgetType: itemStr })
.success(function (data) {
var the_string = itemStr;
var model = $parse(the_string);
model.assign($scope, data);
$scope.$apply();
})
.error(function (error) {
console.error(error);
toastr.error('An error occured, unable to load ' + itemStr);
});
});
This is the code that doesn't work. it complains with the error '$parse' is undefined
. I took this example from a SO post.
I basically want to be able to loop through my itemsliststrings, post the string to an web method, and set the return data for this to a model variable called that particular string. So when I take the "department" string, I submit this string to the web method, I get a data object back, which I then set to the $scope.department object.
Thanks
Upvotes: 0
Views: 863
Reputation: 981
Did you inject the $parse provider in your controller?
.controller('yourController',function($scope,$parse,etc..){});
Upvotes: 1