what is the best way to update add new property to existing object from another function via click event?
this is my existing method that already has object
function another() {
$scope.baseProduct = {
prop1: 'ABC',
prop2: 'DEF',
prop3: 'GHI',
// need to add newProp: true through showEligibleOffer()
}
}
i need to access another()
in my showEligibleOffer()
to add one more new property called 'newProp: true' if checkbox is checked, otherwise newProp: false
so what I've done is
<div ng-app="app" ng-controller="demo">
<input type='checkbox' ng-click='showEligibleOffer($event)' ng-model='showOffer' />
<p ng-if='showOffer'>
hello
</p>
</div>
$scope.showEligibleOffer = function(e) {
$scope.showOffer = !$scope.showOffer;
var evt = e.target.checked;
if ($scope.showOffer) {
$scope.baseProduct = {
newProp: evt
}
}
console.log('new prop', $scope.baseProduct);
}
when do console.log after check and uncheck, not able to read $scope.baseProduct completly but instead its only showing like this
"new prop", {
newProp: true
}
here I need help for below on
- better way to add new property to existing object
- pass true/false to that newly added property based on check and uncheck without duplicating the existing original object
Thanks for the help every one