问题
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:
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.
来源:https://stackoverflow.com/questions/56663223/how-to-include-an-angular-7-application-in-an-existing-html-file-and-website