search

Home  >  Q&A  >  body text

angular.js - angularjs {{}}疑问

在html的界面中 {{a}}为什么输出的是

html<span class="ng-binding ng-scope">
4
</span>

而我期望的是

html4

是否有遇到过的大神帮忙解惑~

PHPzPHPz2743 days ago557

reply all(4)I'll reply

  • 为情所困

    为情所困2017-05-15 16:53:54

    Quoted from the official website:

    The ngBind attribute tells Angular to replace the text content of the
    specified HTML element with the value of a given expression, and to
    update the text content when the value of that expression changes.

    means just ngBind会告诉angular去将你写的表达式替换成一个特殊的html元素.

    And this 特殊的html元素 is the span with class,

    Double curly brackets{{}}ngBind是一样的,实际上是一个directive, there is only a slight difference in the scope of application

    Official Document ngBind

    reply
    0
  • 淡淡烟草味

    淡淡烟草味2017-05-15 16:53:54

    The HTML value output by AngularJs ng-bind will definitely not be just 4. Otherwise, how to control the position of the output value?

    reply
    0
  • PHP中文网

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

    aHow is the value of this variable assigned?
    Generally $scope.a=4;
    The output result of {{a}} is 4.

    reply
    0
  • 伊谢尔伦

    伊谢尔伦2017-05-15 16:53:54

    Thanks for the invitation. You can see it in the source code of angular https://github.com/angular/angular.js/blob/master/src/ng/compile.js#L1...
    In fact, it is used to bind data to this "top text node"

    reply
    0
  • Cancelreply