search

Home  >  Q&A  >  body text

angular.js - Questions about ng-model and ng-bind

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?

某草草某草草2784 days ago620

reply all(3)I'll reply

  • 黄舟

    黄舟2017-05-15 16:55:53

    <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
    

    reply
    0
  • 習慣沉默

    習慣沉默2017-05-15 16:55:53

    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().

    reply
    0
  • PHP中文网

    PHP中文网2017-05-15 16:55:53

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

    reply
    0
  • Cancelreply