[AngularJS] Modal的Scope Bug

今天在使用ui.bootstrap.modal時遇到一個奇怪的問題,透過ng-modal繫結的資料在View可以呈現即時更新的資料,但在controoler卻無法取回。
程式如下:

html

紅框內可正確呈現雙向繫結的資料
image

js.controller

$scope的change事件無法取到selectItem..
image

本以為是我程式或哪邊的設定用錯了,找了相關文章後,發現stackoverflow也有人遇到相關的問題。說由於在modal有屬於自已的controller範圍,所以要透過$parent來強迫繫結才可以。
程式修改如下:
image

加上$parent後,在controller就可以取到selectItem......但個人不確定這是否為最佳解決方法...,因加上$parent後,整個觀念怪怪的,感覺得往上繫結一層,但實際是繫結自己.....=.=。

後記

2014/10/08 : 此bug的版本為0.11.0,在9/26的0.11.2已修正

完整程式

See the Pen ng-model in modalPopup by kimxinfo (@kimxinfo) on CodePen.


參考文章

 
http://stackoverflow.com/questions/18991998/ui-bootstrap-modal-scope-bug
http://stackoverflow.com/questions/18924577/scope-issues-with-angular-ui-modal

這個網誌中的熱門文章

IIS 設定只允許特定IP進入