0

I would like to NOT bind javascript local value to $scope function automatically, but angular did.

javascript code

    var startat = true;
    $scope.chagneStart = function() { startat = !startat}
    $scope.isStart = function() { return angular.copy( startat); }

html code

<checkbox ng-click="chagneStartAt()">
<tr ng-show="isStartAt()"> ... </tr>

When I cliked checkbox, tr tag would be show or not depend on start value. I want to NOT change tr tag until call some other function, like applyOption().

3
  • 4
    Your question is not clear to me :) Commented Jul 11, 2017 at 6:38
  • Provide your html code too. Commented Jul 11, 2017 at 6:43
  • Sorry for unclear question. I added some html code. Commented Jul 11, 2017 at 6:45

2 Answers 2

1

The problem is that you are calling the function inside <tr></tr> tag (ng-show="isStartAt()") which is incorrect here.

Actually, what happens, it calls the function repeatedly. You can check this by keeping console.log('') in your function named isStartAt().

So when you click on checkbox, the function chagneStart() gets called. And it updates the value of var startat. And because your tag function isStartAt() is calling repeatedly, so it also returns the updated value of startat.

So just replace your code with the below one.

Controller

 var startat = true;
 $scope.chagneStart = function() { startat = !startat}
 $scope.isStart = angular.copy(startat);

HTML

<checkbox ng-click="chagneStartAt()">
<tr ng-show="isStartAt"> ... </t
Sign up to request clarification or add additional context in comments.

Comments

1

At this case you should have oldStartat variable:

Javascript:

var startat, oldStartat = true;    
$scope.chagneStart = function() { startat = !startat}
$scope.applyOption = function() { oldStartat = startat; }

HTML:

<checkbox ng-click="chagneStart()">
<tr ng-show="oldStartat">...</tr>
<input type='button' ng-click='applyOption()' value='Apply'>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.