如何在现有的 html 文件和网站中包含 Angular 7 应用程序? [英] How to include an Angular 7 application in an existing html file and website?
问题描述
一方面我有一个现有的网站,另一方面我有一个 Angular 7 应用程序组件.
我想编辑我现有的 someusecase.html
并像这样重用我的 Angular 7 应用程序
<头><meta charset="utf-8"><title>如何导入 Angular 7 应用程序?</title><base href="/"><meta name="viewport" content="width=device-width, initial-scale=1">头部><身体><app-root></app-root></html>
我需要在 html 中包含什么才能使其工作?我在例如相当于:
<script src="/ui/node_modules/angular/angular.min.js"></script><script src="/ui/components/Application.js"></script>
换句话说,是否可以在现有网页内的
1) 运行
ng 构建
2) 进入dist
文件夹
3) 复制 &将所有文件粘贴到您的原始应用中,除了index.html
文件.
4) 打开未复制的index.html
文件
5) 将此文件中的所有 标记复制到您的
someusecase.html
文件中,在同一位置.
6) 在您希望显示 Angular 应用程序的任何位置使用您的应用程序组件选择器.
请注意,这只是信息性的:在现实生活中,这应该是自动化的,因为您必须在每次构建中都进行这种操作.
I have on one side an existing website, on the other I have an Angular 7 application component.
I'd like to edit my existing someusecase.html
and reuse my Angular 7 application like so e.g.
<html lang="en">
<head>
<meta charset="utf-8">
<title>How to import Angular 7 App?</title>
<base href="/">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<app-root></app-root>
</body>
</html>
What would I need to include in the html for this to work? I'm after e.g. something equivalent to:
<script src="/ui/node_modules/angular/angular.min.js"></script>
<script src="/ui/components/Application.js"></script>
In other words, is it possible to reuse and activate an Angular 7 Application within a <div>
scope inside an existing webpage?
1) Run
ng build
2) got into the dist
folder
3) Copy & paste all of the files there, to your original app, except for the index.html
file.
4) Open the not-copied index.html
file
5) Copy all of the <script>
tags in this file, into your someusecase.html
file, at the same spot.
6) use your app component selector wherever you want your angular application to be displayed.
Note that this is only informational : in real life, this should be automated, because you would have to do this manipulation on every build.
这篇关于如何在现有的 html 文件和网站中包含 Angular 7 应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!