2017-01-29 89 views
0

你好,我是新來的角2,學習,試圖建立路線。Angular2 404 GET/traceur

app.routing.ts

import {FormApp} from './app.form'; 
    import {Routes, RouterModule} from '@angular/router'; 

    const appRoutes = [ 
     {path:'form',component:FormApp}, 
     {path:'all',pathMatch:'full',redirectTo:'all'} 
    ]; 

    export const routing = RouterModule.forRoot(appRoutes); 
**app.module.ts** 


     import {NgModule} from "@angular/core"; 
     import {BrowserModule} from "@angular/platform-browser"; 
     import {AppComponent} from "./app.component"; 
     import {AppMedia} from './app.media'; 
     import {FavoriteDirective} from './app.fav.directive'; 
     import { CustomPipe} from './app.pipe'; 
     import {ReactiveFormsModule} from '@angular/forms'; 
     import {FormApp} from './app.form'; 
     import {Service} from './app.service'; 
     import {varijablaTok, varijabla} from './app.tok'; 
     import {routing} from'./app.routing'; 

     const data = {velicina:['M','S','XXL']}; 

     @NgModule({ 
      imports:[BrowserModule, ReactiveFormsModule,routing], 
      declarations:[ AppComponent, AppMedia, FavoriteDirective, CustomPipe, FormApp], 
      bootstrap:[ AppComponent], 
      providers:[Service,{ 
       provide: 'varijablaTok' ,useValue :varijabla 
      }] 



     }) 



export class AppModule {} 

和HTML文件

<!DOCTYPE html> 
<html lang="en"> 
<head> 
    <meta charset="UTF-8"> 
    <title>Title</title> 
</head> 
<body> 
<p id="par">Bozic je sevaju prangije i cesnicu baka sprema</p> 
<media-app [ngClass]="{'crveno ' : n.name === 'Firebug','plavo' : n.name ==='The Redemption' }" *ngFor="let n of xxx" (delete)="naDeletu(mediaItem)" [mediaItem]="n"></media-app> 
<select> 
    <option *ngFor="let d of varijabla.velicina">{{d}}</option> 
</select> 
<router-outlet></router-outlet> 
</body> 
</html> 

我想使用的路由器出口標籤航線formApp成分,但我有錯誤無法獲得/traceur.Am我做錯事我是新來angular2幫助是必要的。 tnx i advance

回答

0

在你的index.html文件中,你需要有應用程序組件的選擇器,因爲那是你的應用程序根目錄。然後在您的應用程序組件的模板中,可以放置一個router-outlet元素。

我猜你的FormApp組件是你想要進入路由器插座。

您的index.html文件:

<body> 
    <app-root></app-root> 
</body 

你AppComponent模板:

<p id="par">Bozic je sevaju prangije i cesnicu baka sprema</p> 
<media-app [ngClass]="{'crveno ' : n.name === 'Firebug','plavo' : n.name ==='The Redemption' }" *ngFor="let n of xxx" (delete)="naDeletu(mediaItem)" [mediaItem]="n"></media-app> 
<select> 
    <option *ngFor="let d of varijabla.velicina">{{d}}</option> 
</select> 
<router-outlet></router-outlet> 
相關問題