Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ambiguous syntax explanation in the $watch tutorial #46

Open
ColinDTaylor opened this issue Mar 17, 2016 · 3 comments
Open

Ambiguous syntax explanation in the $watch tutorial #46

ColinDTaylor opened this issue Mar 17, 2016 · 3 comments

Comments

@ColinDTaylor
Copy link

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;
    }]);
@GauntStrelok
Copy link

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]);"

@levibotelho
Copy link
Owner

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.

@prayagKhanal
Copy link

i later figured out how to use $watch thank you i understood more going into the documentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants