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
1 Answer
Reset to default 7You'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条)