在 iis 上发布时出现 Angular 2 错误

标签 angular iis

我已经在 Angular 2 中创建了演示应用程序,当我在本地运行它时它工作正常但当我在 iis serve 上发布它时出现错误。

我收到这个错误

Failed to load resource: the server responded with a status of 404 (Not Found)

enter image description here

这是我的代码index.html

<!doctype html>
<html>
<head>
  <meta charset="utf-8">
  <title>MyApp</title>
  <base href="/">
  <link rel="stylesheet" href="https://bootswatch.com/darkly/bootstrap.min.css">  
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="icon" type="image/x-icon" href="favicon.ico">
  <script>
    System.import('app').catch(function(err){ console.error(err); });
  </script>
</head>
<body>
  <app-root>Loading...</app-root>
</body>

</html>

app.router.ts

import {ModuleWithProviders} from '@angular/core';
import {Routes,RouterModule} from '@angular/router'; 

//import {AppComponent} from './app.component'
import {AboutComponent} from './about/about.component'
import {TechnologyComponent} from './technology/technology.component'

export const router : Routes = [
    {path:'',redirectTo:'about',pathMatch:'full'},
    {path:'about',component:AboutComponent},
    {path:'tachnology',component:TechnologyComponent}
]
export const routes: ModuleWithProviders = RouterModule.forRoot(router)

app.module.ts

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { HttpModule } from '@angular/http';

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

import {routes} from './app.router'
import { AppComponent } from './app.component';
import { AboutComponent } from './about/about.component';
import { TechnologyComponent } from './technology/technology.component';

import {AboutSrvice} from './about/about.service'
@NgModule({
  declarations: [
    AppComponent,
    AboutComponent,
    TechnologyComponent,
  ],

  imports: [
    BrowserModule,
    FormsModule,
    HttpModule,
    routes
  ],
  //There is two ways you can use service first here you can add service in provider or either you can add it in about.component.ts file in @Component({}) section 
 // providers: [AboutSrvice,{provide: LocationStrategy, useClass: HashLocationStrategy}],
 providers: [AboutSrvice],
  bootstrap: [AppComponent]
})
export class AppModule { }

我是否遗漏了什么或需要任何额外的内容才能发布?

最佳答案

发现是版本冲突

让我们玩吧:D

npm uninstall -g @angular/cli
npm cache clean

然后在那之后

npm install -g @angular/cli@latest --save

在新文件夹中创建新项目

ng 新项目名称

关闭编辑器

将旧项目的src复制到新项目

运行编辑器

构建和部署

ng build --prod --aot --no-sourcemap --base-href

关于在 iis 上发布时出现 Angular 2 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46704470/

相关文章:

angular - Ionic 2 HTTP Provider 第一次返回未定义,但第二次返回正确的数据

angular - 你如何在 Angular 上全局配置 moment.js?

asp.net - 无法修改 machine.config 文件

php - 如何从 PHP 表单执行数据库插入

c# - 清除浏览器历史记录后网站无法正常工作

angular - 类型 never 上不存在属性 "url"?

javascript - 在 html 页面中显示来自 Angularjs2 文件 (.ts) 的数据

javascript - 如何将数据从 API 加载到 Angular 2 中的数组中?

windows - IIS7 上的 Laravel 5 不适用于 web.config

ssl - IIS 8.5 上带有通配符证书的 SNI