Strange one-way binding in Angular-UI Modal

倾然丶 夕夏残阳落幕 提交于 2019-12-24 07:05:57

问题


I am running into a strange one way binding behavior within a Angular-UI-Bootstrap Modal.

Inside a modal html, two day data binding seems to work fine but the scope variable model at the controller does not update for some reason.

If, however, the scope variable is an object, then the two way binding seems to propagate to the controller.

Does anyone know why this is happening? Anyway to fix it?

I have made a plunker to demonstrate the problem.

One way binding in Modal problem


回答1:


This seems to be the most common problem I see people having with angular; nested scopes. Have a look at the following resource: http://jimhoskins.com/2012/12/14/nested-scopes-in-angularjs.html

This essentially boils down to the following. If you attempt to access $scope.someVal, angular will search up the parent chain looking for someVal, and if found will return it to you. If you try and change someVal, it will simply create a new someVal to the current scope.

If however you attempt to access $scope.someObj.someVal, reading acts the same way. Except this time if you try to change someVal, it will change the value inside someObj, no matter which scope is commanding the update.



来源:https://stackoverflow.com/questions/22115470/strange-one-way-binding-in-angular-ui-modal

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!