Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular 2 error when publish on iis

Tags:

iis

angular

I have created demo application in angular 2, its working fine when i run it on local but getting error while i published it on iis serve.

This error i am getting

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

enter image description here

Here is my code 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 { }

Is there am i missing something or need any extra content for publish?.

like image 871
Bharat Avatar asked Oct 18 '22 04:10

Bharat


1 Answers

it terns out that it is a conflict in versions so

let us play :D

npm uninstall -g @angular/cli
npm cache clean

then after that

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

create new project in a new folder

ng new TheProjectName

close the editor

copy src from the old project to the new project

run the editor

build and deploy

ng build --prod --aot --no-sourcemap --base-href
like image 162
Tarek.Eladly Avatar answered Nov 15 '22 10:11

Tarek.Eladly