Strange one-way binding in Angular-UI Modal

2019-08-01 05:30发布

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条回答
迷人小祖宗
2楼-- · 2019-08-01 05:35

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.

查看更多
登录 后发表回答