【问题标题】:css is not applied to the appended html elements by angular.js?angular.js 没有将 css 应用于附加的 html 元素?
【发布时间】:2015-09-05 20:12:56
【问题描述】:

我已经像这样通过 angular.js 将一些 html 附加到 div 中

  var myEl = angular.element( document.querySelector( '#form' ) );
  myEl.append(
    '<div layout="row" layout-wrap layout-padding >'+
      '<div flex = "50" flex-sm = "100" flex-md = "100" flex-lg = "50">'+
        '<div layout = "row" layout-align = "center center">'+
          '<img class="md-avatar">'+
        '</div>'+
        '<div layout = "row" layout-align = "center center">'+
          '<md-button class="md-raised" style="width: 200px;white-space: normal;line-height: 12px;">'+
            '<i class="fa fa-upload"></i>'+
            'Upload New Image'+
          '</md-button>'+
        '</div>'+
      '</div>'+
      '<div flex = "50" flex-sm = "100" flex-md = "100" flex-lg = "50">'+
        '<i class="fa fa-trash-o" style = "float:right;"></i>'+
        '<md-input-container flex>'+
          '<label>Name</label>'+
          '<input type="text" >'+
        '</md-input-container>'+

        '<md-input-container flex>'+
          '<label>Title</label>'+
          '<input type="text" >'+
        '</md-input-container>'+

        '<md-input-container flex>'+
          '<label>Email</label>'+
          '<input type="email" >'+
        '</md-input-container>'+

        '<md-input-container flex>'+
          '<label>Telephone</label>'+
          '<input type="text" >'+
        '</md-input-container>'+
      '</div>'+
    '</div>'
  );

但是最近添加的元素没有采用网站的 css,我使用 Angular-material 作为 css 框架。

请指导我解决这个问题以及我应该解决什么问题。

【问题讨论】:

  • angular 在不使用 $compile 的情况下将指令附加到 DOM 时不会编译指令

标签: javascript css angularjs material-design angular-material


【解决方案1】:

你忘了编译它

这样试试

$compile(myEl.contents())($scope);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-09-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-23
    • 2019-03-25
    相关资源
    最近更新 更多