Skip to content

Ambiguous syntax explanation in the $watch tutorial #46

@ColinDTaylor

Description

@ColinDTaylor

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

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions