Angular 2 application with no server?

2019-09-15 12:16发布

问题:

How to run Angular 2 application without running a server? I need to take just one folder which contains index.html (some css, js additionally)

回答1:

If you use angular-cli you can do ng build --prod. The index.html will be in the dist folder.



回答2:

Completing Admir Sabanovic's answer. In your app.module.ts add as provider

providers: [
   { provide: LocationStrategy, useClass: HashLocationStrategy }
]

In your index.html change the line < base href="./" > by

<script>document.write("<base href='"+window.location.href+"'/>") </script>