【发布时间】:2017-02-22 15:38:18
【问题描述】:
如何在不运行服务器的情况下运行 Angular 2 应用程序? 我只需要一个包含 index.html 的文件夹(另外还有一些 css、js)
【问题讨论】:
-
您可以简单地使用 node js 安装 Angular 包,在此处进一步阅读:angular.io/docs/js/latest/quickstart.html
标签: node.js angular typescript
如何在不运行服务器的情况下运行 Angular 2 应用程序? 我只需要一个包含 index.html 的文件夹(另外还有一些 css、js)
【问题讨论】:
标签: node.js angular typescript
如果您使用 angular-cli,您可以使用 ng build --prod。 index.html 将在 dist 文件夹中。
【讨论】:
index.html,而不仅仅是在浏览器中打开文件。查看浏览器控制台,index.html 尝试加载的所有 js/css 文件可能都出现 404 错误。
完成 Admir Sabanovic 的回答。在您的 app.module.ts 中添加为提供者
providers: [
{ provide: LocationStrategy, useClass: HashLocationStrategy }
]
在您的 index.html 中将
<script>document.write("<base href='"+window.location.href+"'/>") </script>
【讨论】: