Ambiguous syntax explanation in the $watch tutorial
In the tutorial for $watch, a functioning example is never given. This is fine, but later on when explaining the syntax of a $watch expression, there's this example:
$scope.$watch([expression returning watched value],
[change handler],
[objectEquality?]);
This teaches the syntax ambiguously, as it's hard to tell whether to input something like this (correct):
angular.module("root", [])
.controller("index", ["$scope", function($scope) {
$scope.$watch("factor", function (newValue) {
$scope.product = newValue * 2;
});
$scope.factor = 6;
}]);
or this (incorrect):
angular.module("root", [])
.controller("index", ["$scope", function($scope) {
$scope.$watch(["factor"],
[function (newValue) {
$scope.product = newValue * 2;
}]);
$scope.factor = 6;
}]);
Tried several times to put an array for the "factor" too, and i get the error, until i searched the Api for the function: https://docs.angularjs.org/api/ng/type/$rootScope.Scope
"$watch(watchExpression, listener, [objectEquality]);"
Good point. If either of you want to change it just do a PR and I'll accept and deploy. Otherwise I'll take care of it when I get the time.
i later figured out how to use $watch thank you i understood more going into the documentation.