我收到此错误
TypeError:$ scope.employeeData未定义
虽然功能应该是正常的。
我的代码:
$scope.$watch('[employeeData.current_manager_id, employeeData.manager_id]', function () {
if ($scope.employeeData.manager_id && $scope.employeeData.current_manager_id == $scope.employeeData.manager_id) {
alert('Already Manager');
$scope.employeeData.manager_id = "";
return false;
}
});
答案 0 :(得分:1)
我为你创建了一个有效的fiddle。希望你能找到你所缺少的东西。控制器看起来像:
function MyCtrl($scope) {
$scope.employeeData = {};
$scope.$watch('employeeData.current_manager_id+employeeData.manager_id', function (newVal, oldVal) {
console.log(newVal, oldVal);
if ($scope.employeeData.manager_id && $scope.employeeData.current_manager_id == $scope.employeeData.manager_id) {
alert('Already Manager');
$scope.employeeData.manager_id = "";
return false;
}
});
}
html是:
<div ng-controller="MyCtrl">
<input type="text" ng-model="employeeData.current_manager_id"/><br/>
<input type="text" ng-model="employeeData.manager_id"/><br/>
{{employeeData}}
</div>