search

Home  >  Q&A  >  body text

angular.js - angularjs动态增加DOM

我是用append动态增加的,但是内容不能绑定了

$("#chat").append("<p class='eve_chat clearfloat'><p style='width:calc(98% - 50px);' class='clearfloat mb10'><img src='../../img/goods/3.jpg' class='chat_face left'><p class='chat_pop_left'><p class='chat_content left'><p>{{messages.messagetxt}}</p></p></p></p></p>")

请问有什么办法么?

ringa_leeringa_lee2744 days ago533

reply all(2)I'll reply

  • 大家讲道理

    大家讲道理2017-05-15 17:07:32

    Because your Html is asynchronous, you need to use the $compile service to compile manually
    Remember to dependency injection $compile

    var el=$compile("HTML代码")(scope); $('#chat').append(el);

    reply
    0
  • 伊谢尔伦

    伊谢尔伦2017-05-15 17:07:32

    Use

     $compile("<p></p>")($scope)
     

    Come and bind~~

    reply
    0
  • Cancelreply