angularjs - 错误:formController 中的 [ng:cpws] 深度观察 - angularJS 1.8.0
问题描述
我有一个带有子控件(输入和文本区域)的 formController 的简单场景。当我使用深度观察者(objectEquality
等于 true)来检查整个表单的变化时,我得到了Error: [ng:cpws]
这是基本代码(使用最新的 angularJS):
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Example - example-forms-simple-production</title>
<script src="//code.angularjs.org/snapshot/angular.min.js"></script>
</head>
<body ng-app="formExample">
<div ng-controller="ExampleController">
<form novalidate class="simple-form" name="formContent">
<label>Name: <input type="text" ng-model="user.name" /></label><br />
<label>Description: <textarea ng_model="user.description"></textarea></label><br />
</form>
<pre>user = {{user | json}}</pre>
</div>
<script>
angular.module('formExample', [])
.controller('ExampleController', ['$scope', function($scope) {
$scope.master = {};
$scope.$watch(() => $scope.formContent, (newValue, oldValue) => {
console.log('new ', newValue);
console.log('old ', oldValue);
}, true);
}]);
</script>
</body>
</html>
控制台中的问题是:
angular.js:15697 Error: [ng:cpws] http://errors.angularjs.org/1.8.2-build.2468+sha.9b3b6f7f7/ng/cpws
at VM469 angular.min.js:7
at e (VM469 angular.min.js:13)
at c (VM469 angular.min.js:13)
at e (VM469 angular.min.js:13)
at c (VM469 angular.min.js:12)
at e (VM469 angular.min.js:13)
at c (VM469 angular.min.js:13)
at e (VM469 angular.min.js:13)
at Ia (VM469 angular.min.js:15)
at m.$digest (VM469 angular.min.js:153)
我不完全理解表单对象中的哪个属性导致了问题。根据 angularJS 文档,这可能是由于循环和自引用引起的
plunker 中的实时代码:https ://plnkr.co/edit/B9n7GAPkZvzsFbKN?preview
解决方案
此处解释了此问题的原因:将 ngModel 作为绑定传递时发生意外的重大更改 基本上,(自 9e24e77 起)我们将范围放在 NgModelController 实例上,因此不再可能复制此类实例(当$观看)。
推荐阅读
- android - contentResolver.openFileDescriptor (Android) 上的 FileNotFoundException EACCES(权限被拒绝)
- python - 通过将分组月份移动 -1 来附加到数据帧
- php - 设计返回 json、pdf、csv 的 rest API
- python - 为什么我会收到 pylint 错误:模块 'socket' 没有 'gethostname' 成员(无成员)?
- matlab - 在matlab中使用小波R检测ECG信号
- c# - 为什么我的按钮监听器除了打印方法不调用任何东西?
- c# - Linq 按连接表中的项目计数分组
- java - 重复类 LifecycleOwner
- python - 如何使用 InlinKeyBoardMarkup 使用多种方法 - 电报机器人
- azure - 如何在主分支中恢复拉取请求?