javascript - How to properly update a scope variable if it's being passed as a parameter -
i'm trying pass scoped object property function in controller , change value either true or false depending on current value. want value updated in scope @ same time.
the problem occurs can't use $scope.isbeingedited
in function update scope, because it's present in ng-repeat wouldn't know 1 update. , setting value of parameter doesn't seem update scope.
i read this question seems state not possible? maybe read wrong surely there must rather simple way of achieving this? causing me problems on more 1 front it's time solve issue.
here's dumb version of markup, containg title, input , edit "button":
<div ng-repeat="bodypart in body"> <h3 ng-hide="bodypart.isbeingedited" ng-bind="bodypart.name"></h3> <input ng-show="bodypart.isbeingedited"> <span ng-click="seteditstate(bodypart.isbeingedited)">edit</span> </div>
when click on "edit" should run, passing bodypart.isbeingedited
variable value check for:
$scope.seteditstate = function(item) { // check if item true or false // , set accordingly item ? item = false : item = true; }
how can ensure scoped variable gets passed function gets updated when item
gets updated?
you can pass item
instead of property isbeingedited
, use in code accordingly:
<span ng-click="seteditstate(bodypart)">edit</span>
controller
$scope.seteditstate = function(item) { item.isbeingedited = !item.isbeingedited; }
Comments
Post a Comment