angular.js - 關(guān)于ng-model和ng-bind的疑問(wèn)
問(wèn)題描述
雙向綁定,一般來(lái)說(shuō)是這樣
<input ng-model='object.xxx'><span ng-bind='object.xxx'></span>
也就是說(shuō)ng-bind是相當(dāng)于{{object.xxx}},是用于展示數(shù)據(jù)的。而ng-model是控制數(shù)據(jù)的。
但在這里,我從后臺(tái)獲取到設(shè)備號(hào)后,輸出到頁(yè)面,對(duì)input使用的是ng-model,使用ng-bind是沒有反應(yīng)的,為什么?
問(wèn)題解答
回答1:<input type='text' ng-value='object.xxx' readonly='readonly' />
http://stackoverflow.com/a/12420157/2586541
$(’#input1’).html(’123’); //ng-bind$(’#input1’).val(’123’); //ng-value回答2:
請(qǐng)問(wèn)你是怎么獲取的設(shè)備號(hào)?
如果是自己實(shí)現(xiàn)的ajax, 則獲取數(shù)據(jù)后 需要 手動(dòng) $scope.$apply();如果是用$http獲取數(shù)據(jù), angular 會(huì)自動(dòng)調(diào)用 $apply().
回答3:ng-bind是從$scope -> view的單向綁定ng-modle是$scope <-> view的雙向綁定
相關(guān)文章:
1. Span標(biāo)簽2. css - 求推薦適用于vue2的框架 像bootstrap這種類型的3. docker-machine添加一個(gè)已有的docker主機(jī)問(wèn)題4. css - 關(guān)于div自適應(yīng)問(wèn)題,大家看圖吧,說(shuō)不清5. 關(guān)docker hub上有些鏡像的tag被標(biāo)記““This image has vulnerabilities””6. SessionNotFoundException:會(huì)話ID為null。調(diào)用quit()后使用WebDriver嗎?(硒)7. android新手一枚,android使用httclient獲取服務(wù)器端數(shù)據(jù)失敗,但是用java工程運(yùn)行就可以成功獲取。8. angular.js使用$resource服務(wù)把數(shù)據(jù)存入mongodb的問(wèn)題。9. java - Collections類里的swap函數(shù),源碼為什么要新定義一個(gè)final的List型變量l指向傳入的list?10. python - django如何每次調(diào)用標(biāo)簽的時(shí)候都取隨機(jī)數(shù)據(jù)
