W
W
werevolff2016-09-16 18:21:14
Angular
werevolff, 2016-09-16 18:21:14

Is using $scope.$watch bad manners?

Heard the opinion that using $scope.$watch is bad form in Angular.js. Is it so? If so, then here's an example:

$scope.modelOne = false;
$scope.modelTwo = 'some string';

The first model is related to the checkbox.
The second one is c input type="text"
If modelOne === true, modelTwo is fully uppercase. If false, then fully convert to lower case. How to do it without $watch, if it's possible to do it at all?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nicholas, 2016-09-16
@werevolff

In your case, you should use ng-change ( https://docs.angularjs.org/api/ng/directive/ngChange ).
And $watch is, yes, a bad thing. Better to avoid it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question