在没有服务器的情况下,在file:///上本地运行Angular 7项目 [英] Run Angular 7 project locally on file:/// without server

查看:127
本文介绍了在没有服务器的情况下,在file:///上本地运行Angular 7项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想构建我的有角度的项目并生成一个包含该项目的ZIP文件,以通过电子邮件发送该文件,并且希望接收该文件的人能够在其桌面上单击index.html文件来打开它.

I want to build my angular project and generate a ZIP file containing it to send it via email and I want the person who receives it to be able to open it on his Desktop clicking index.html file.

我将baseUrl更改为./或document.location,但是出现以下错误:未处理的导航错误"

I changed the baseUrl to ./ or to document.location but I'm getting the following error: "Unhandled Navigation Error"

有人对如何解决此问题有任何提示吗?

Does anyone have any hint about how to fix this?

推荐答案

您可以在index.html文件上双击运行角度应用程序.只需在app.module.ts

You can run angular app on double click on index.html file. Just add below code in your app.module.ts

请注意:从index.html文件中删除baseUrl = ./

note that : remove baseUrl = ./ from index.html file

//in App.module.ts : 

//import these packages  

import { APP_BASE_HREF, LocationStrategy, HashLocationStrategy } from '@angular/common';


// add these packages into providers as below : 

@NgModule({
    imports: 
     [
      .....
     ],
    declarations: 
     [
     ....
     ],
    providers: 
      [
        ....
        { provide: APP_BASE_HREF, useValue: '/' },
        { provide: LocationStrategy, useClass: HashLocationStrategy },
        
        ....
       ]
   ....
   
   })
   
   export class Appmodule{}

现在执行:npm run build,然后双击dist文件夹中的index.html文件. 您的应用程序应运行.

Now execute : npm run build and double click the index.html file from dist folder. You app should run.

这篇关于在没有服务器的情况下,在file:///上本地运行Angular 7项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆