I'm getting an error when I run the 'getPriceSummary' function below more than once. I call the function from the UI and then add one part of JSON to another and send it off to an API...
(function() {
var quoteBuild = angular.module('quoteApp');
quoteBuild.controller('builderController', function($scope) {
$scope.priceSummaryRequest = {
"Groups": [{
"Products": []
},
// other stuff
]
};
// this is dynamically created in the UI - this is just an examply of whats created
$scope.selectedProducts.Products = [{
"ProductCode": "Code1",
}, {
"ProductCode": "Code1",
}, ]
$scope.getPriceSummary = function() {
$scope.priceSummaryRequest.Groups[0].Products.push.apply($scope.priceSummaryRequest.Groups[0].Products, $scope.selectedProducts.Products);
// get prices back from the api
productsServices.getSolutionPrice($scope.priceSummaryRequest)
.then(function(res) {})
.finally(function() {});
}
});
}());
As mentioned, the first time $scope.getPriceSummary runs it works, but if I run it again I get this error
TypeError: object is not a function
at hb.functionCall (https://ajax.googleapis....)
at Cc.(anonymous function).compile.d.on.f (https://ajax.googleapis....)
at l.$get.l.$eval (https://ajax.googleapis....)
at l.$get.l.$apply (https://ajax.googleapis....)
at HTMLTableRowElement.<anonymous> (https://ajax.googleapis...)
at HTMLTableRowElement.n.event.dispatch (https://ajax.googleapis...)
at HTMLTableRowElement.n.event.add.r.handle (https://ajax.googleapis...)
(anonymous function)angular.js:8548 $getangular.js:14489 $get.l.$applyangular.js:21427 (anonymous function)jquery.min.js:3 n.event.dispatchjquery.min.js:3 n.event.add.r.handle
which I think is related to where I am doing the push.apply. Any ideas what I am doing wrong?
EDIT I'm not sure if this relevant, but I call the getPriceSummary function from a table row like this
<tr ng-click="getPriceSummary(I pass prices in here - just removed it)" ng-repeat="prices in productVariant.Prices">