AngularJS changing deep scope object value -
hit bit of brick wall here hoping guidance.
i'm building scope variable called 'display' built off 2 http calls haven't included keep simple. i'm doing adding product types each category object.
$scope.display = {}; portal.fetchcategories().then(function(data) { $scope.categories = data.categories; return portal.fetchproducttypes(); }) .then(function(data) { $scope.producttypes = data.product_types; angular.foreach($scope.categories, function(value) { $scope.display[value.id] = { title: value.title, start: value.start, end: value.end, product_types: $scope.producttypes }; }); })
this works fine.
the trouble i'm having when target product type inside category , attempt update title:
$scope.display[2].product_types[0]['title'] = "updated title";
it updating product type title in categories rather specified category. suspect it's updating $scope.producttypes.
can shed light on i'm doing wrong?
problem same object reference associated product types display. can overcome making copy of producttypes
, if suffices , not problem.
angular.foreach($scope.categories, function(value) { $scope.display[value.id] = { title: value.title, start: value.start, end: value.end, product_types: angular.copy($scope.producttypes) }; });
Comments
Post a Comment