[英]Created Angular component not visible after 'ng build'
I'm new to Angular and recently I started working on a simple personal SPA project.我是 Angular 的新手,最近我开始从事一个简单的个人 SPA 项目。 It was created using the angular cli, and the folder structure is nothing special:
它是使用 angular cli 创建的,文件夹结构没有什么特别之处:
- myApp
----e2e
----node_modules
----src
--------app
------------ main app module with two .ts components and html for each of them
...
Everything works fine when I use ng serve
: I can see my components on localhost:4200
and Angular's functionality works as a charm.当我使用
ng serve
时一切正常:我可以在localhost:4200
上看到我的组件,Angular 的功能很有魅力。
However, when I run ng build
and from inside the newly created dist
folder I open index.html
, I can't see my components at all.但是,当我运行
ng build
并从新创建的dist
文件夹中打开index.html
,我根本看不到我的组件。
The index.html
file is as follows: index.html
文件如下:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>RoutingDemo</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="favicon.ico">
</head>
<body>
<app-root></app-root>
<script type="text/javascript" src="runtime.js"></script><script type="text/javascript" src="polyfills.js"></script><script type="text/javascript" src="styles.js"></script><script type="text/javascript" src="vendor.js"></script><script type="text/javascript" src="main.js"></script></body>
</html>
I get no errors in the console for missing files and all of the JS and CSS files are being successfully read by the index.html.我在控制台中没有因丢失文件而出错,并且 index.html 正在成功读取所有 JS 和 CSS 文件。
Can someone explain why am I not seeing the components?有人可以解释为什么我没有看到组件吗?
所以你需要为你的页面提供服务,最简单的方法是在你的dist
文件夹中执行npm i -g http-server
并从命令 lint 运行http-server
,然后你将能够看到你的页面
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.