[英]$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.