是否可以将数据从angular7组件或服务传递到index.html文件? [英] Is it possible to pass data from an angular7 component or service to index.html file?

查看:92
本文介绍了是否可以将数据从angular7组件或服务传递到index.html文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在Angular7应用程序的index.html文件中定义一个具有动态数据的对象.Angular应用程序运行时是否可以在index.html中发送和更新数据?

I am trying to define an object with dynamic data in index.html file of an Angular7 application. Can I send and update data in index.html while the angular application is running?

推荐答案

您可以为元素分配 id .然后使用 getElementById('id')获得该元素并为其分配数据.

You could assign an id to the element. Then obtain the element using getElementById('id') and assign data to it.

index.html

index.html

<my-app>loading</my-app>
<div id="indexDiv">/div>

组件

document.getElementById('indexDiv').innerHTML = "Updated from component"

这篇关于是否可以将数据从angular7组件或服务传递到index.html文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆