javascript - $scope.$watch(var,function) undefined is not a function - Stack Overflow

I have this error: "undefined is not a function" ming up when trying to add a watch to the sc

I have this error: "undefined is not a function" ming up when trying to add a watch to the scope.

I can't find the error. Maybe i am just blind staring at this error for to long now. Why do i get a undefined function error when the $watch method is clearly defined on the scope ?

chColorPicker.controller('chColorPickerCtrl', function ($scope,$document,$element) {


    $scope.init = function (event)
    {

    }

    var colorObject = {
        r:'0', 
        g:'0', 
        b:'0', 
        hex:'#000000'
    };
    $scope = colorObject;
    $scope.Z1;
    $scope.Z2;

    var onChangeColor = function(newValue,oldValue)
    {
        console.log('change');
    }

    $scope.$watch("r",onChangeColor); //<-- the error appears here.
});

I have this error: "undefined is not a function" ming up when trying to add a watch to the scope.

I can't find the error. Maybe i am just blind staring at this error for to long now. Why do i get a undefined function error when the $watch method is clearly defined on the scope ?

chColorPicker.controller('chColorPickerCtrl', function ($scope,$document,$element) {


    $scope.init = function (event)
    {

    }

    var colorObject = {
        r:'0', 
        g:'0', 
        b:'0', 
        hex:'#000000'
    };
    $scope = colorObject;
    $scope.Z1;
    $scope.Z2;

    var onChangeColor = function(newValue,oldValue)
    {
        console.log('change');
    }

    $scope.$watch("r",onChangeColor); //<-- the error appears here.
});
Share Improve this question asked Feb 1, 2015 at 0:30 BongoBongo 3,1835 gold badges43 silver badges73 bronze badges 1
  • 4 Maybe because of this - $scope = colorObject; ;). – Pavel Horal Commented Feb 1, 2015 at 0:33
Add a ment  | 

1 Answer 1

Reset to default 7

You're changing $scope:

$scope = colorObject;//error in this line

So, you get error when you use $scope.$watch() as it's not calling angular's $scope anymore.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745083973a4610293.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信