[英]Angular view (DOM elements) not being updated when model changes
Running latest stable version of Angular in latest stable Chrome. 在最新稳定的Chrome中运行最新的稳定版Angular。 I have an ng-click on a DOM element that's inside a view with ng controller A, but the DOM element itself has an ng-controller set to another controller, B. ng-click fires inside controller B, however changes to scope properties, which DOM element is bound to by its ng-model attribute, are not reflected.
我在ng控制器A的视图中使用了一个DOM元素,但DOM元素本身有一个ng控制器设置到另一个控制器,B.ng-click在控制器B内部触发,但是更改为范围属性,不反映哪个DOM元素由其ng-model属性绑定。
Specifically I have a textarea, as well as other HTML5 input types. 具体来说,我有一个textarea,以及其他HTML5输入类型。 No errors, and when I break in the debugger, I can look at the scope variable and see that $scope is in fact pointing to controller B.
没有错误,当我打破调试器时,我可以查看范围变量并看到$ scope实际上指向控制器B.
Plnkr example here, notice how it only updates the input that's inside the same DIV?: http://plnkr.co/edit/DmccNj?p=preview 这里的Plnkr示例,请注意它是如何仅更新同一DIV中的输入的?: http ://plnkr.co/edit/DmccNj?p = preview
I had the same issue just recently. 我刚才遇到了同样的问题。 Apparently, when you create two HTML fragments with the same
ng-controller
, it creates two separate instances of the controller. 显然,当您使用相同的
ng-controller
创建两个HTML片段时,它会创建两个独立的控制器实例。 So, hitting the 'EDIT' button sets $scope.comment
in instance 1, but the input field is bound to instance 2 of the controller. 因此,点击“编辑”按钮
$scope.comment
在实例1中设置$scope.comment
,但输入字段绑定到控制器的实例2。
If you must do it this way, you're best of creating an angular service, as they are singletons. 如果你必须这样做,你最好创建一个有角度的服务,因为他们是单身人士。
Here is my question: Splitting HTML components for one controller causes controller to stop working 这是我的问题: 为一个控制器拆分HTML组件会导致控制器停止工作
Also, Angular Batarang is a very cool Chrome extension from the AngularJS team to debug Angular applications. 此外, Angular Batarang是AngularJS团队非常酷的Chrome扩展,用于调试Angular应用程序。 I mention this because if you (or I) had used this, we would have instantly seen what was going wrong.
我之所以提到这一点,是因为如果你(或我)使用了这个,我们会立即看到出了什么问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.