anjularJS 中雙向綁定失效

今天遇到一個問題:在controller中有一個域屬性:$scope.state,對應的頁面中<span>{{state}}</span>.當在controller中改變$scope.state的值得時候,頁面中不能一起同步改變。

解決方法:在controller中定義state屬性的時候,寫成對象的形式。如

$scope.switch = {

state:true

}

在頁面中獲取的時候:<span>{{switch.state}}</span>.這樣就能獲取到了。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章