简体   繁体   English

$ scope。$ watch(var,function)未定义不是函数

[英]$scope.$watch(var,function) undefined is not a function

I have this error: "undefined is not a function" comming 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 ? 为什么在范围内明确定义$ watch方法时会出现未定义的函数错误?

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

You're changing $scope: 你正在改变$ 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. 因此,使用$ scope。$ watch()时会出错,因为它不再调用angular的$ scope。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 AngularJS $ scope。$ watch回调函数参数在Jasmine测试中未定义 - AngularJS $scope.$watch callback function parameter undefined in Jasmine test $ scope。$ watch函数不能反映变化吗? - $scope.$watch function does not reflect changes? 传递给$ scope。$ watch函数的“作用域”是什么? - What is the “scope” that gets passed to a $scope.$watch function? $ scope。$ watch…使它在另一个作用域上返回一个函数? - $scope.$watch … make it return a function on another scope? $ scope。$ apply返回未定义的错误不是函数 - $scope.$apply return error of undefined is not a function 角度$ scope。$ watch关于数组调用更新功能 - angular $scope.$watch on array calling update function 将scope。$ watch值返回到指令的链接函数 - returning scope.$watch value to a link function of a directive 了解带范围的窗口大小调整事件。$ apply with $ watch on a function - Understanding window resize event with scope.$apply with $watch on a function $ scope。$ watch函数未按预期触发nodelist.length更改 - $scope.$watch function not firing on nodelist.length change as expected $ location.search()-如何使用$ scope。$ watch函数中作用域的参数? - $location.search() - how to use params from scope inside $scope.$watch function?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM