angular.js - Questions about ng-model and ng-bind
某草草
某草草 2017-05-15 16:53:53
0
3
603

Two-way binding, generally speaking is like this

<input ng-model="object.xxx">
<span ng-bind="object.xxx"></span>

In other words, ng-bind is equivalent to {{object.xxx}}, which is used to display data. And ng-model controls data.

But here, after I get the device number from the background, I output it to the page. I use ng-model for input, but there is no response when using ng-bind. Why?

某草草
某草草

reply all(3)
黄舟
<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
習慣沉默

How did you obtain the device number?

If you implement ajax yourself, you need to manually $scope.$apply();
after getting the data If $http is used to obtain data, angular will automatically call $apply().

Ty80

ng-bind is a one-way binding from $scope -> view
ng-modle is a two-way binding from $scope <-> view

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template