【问题标题】:get HTML element from template in Angular 7 [duplicate]从Angular 7中的模板获取HTML元素[重复]
【发布时间】:2019-08-20 11:39:35
【问题描述】:

有没有办法在我的 app.module.ts 文件中获取我的“# content”变量?

我的 HTML 示例文件

   <div #content>
      .....
   </div>

我的示例 app.module.ts 文件

    //How do I get my variable here?

【问题讨论】:

标签: angular


【解决方案1】:

您可以通过以下方式访问它:

@ViewChild('content') content: ElementRef;

这里有更深入的了解: https://medium.com/@toannm4/angular-nativeelement-how-to-read-nativeelement-using-viewchild-cdf4a0970482

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-06
    • 2023-01-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多