我可以利用一些幫助在這個,我瞭解ANGULAR 2路由,我得到這個錯誤:角2個錯誤指令
app/app.component.ts(7,12): error TS2345: Argument of type '{ selector: string; templateUrl: string; directives: (typeof PeliculasListComponent | typeof Peli...' is not assignable to parameter of type '{ selector?: string; inputs?: string[]; outputs?: string[]; properties?: string[]; events?: strin...'. Types of property 'directives' are incompatible. Type '(typeof PeliculasListComponent | typeof PeliculasFooterComponent | typeof "C:/UwAmp/www/curso-ang...' is not assignable to type '(Type | any[])[]'. Type 'typeof PeliculasListComponent | typeof PeliculasFooterComponent | typeof "C:/UwAmp/www/curso-angu...' is not assignable to type 'Type | any[]'. Type 'typeof "C:/UwAmp/www/curso-angular/app/components/contacto.component"' is not assignable to type 'Type | any[]'. Type 'typeof "C:/UwAmp/www/curso-angular/app/components/contacto.component"' is not assignable to type 'any[]'. Property 'length' is missing in type 'typeof "C:/UwAmp/www/curso-angular/app/components/contacto.component"'. app/app.component.ts(16,14): error TS2345: Argument of type '({ path: string; name: string; component: typeof PeliculasListComponent; useAsDefault: boolean; }...' is not assignable to parameter of type 'RouteDefinition[]'. Type '{ path: string; name: string; component: typeof PeliculasListComponent; useAsDefault: boolean; } ...' is not assignable to type 'RouteDefinition'. Type '{ path: string; name: string; component: typeof "C:/UwAmp/www/curso-angular/app/components/contac...' is not assignable to type 'RouteDefinition'. Types of property 'component' are incompatible. Type 'typeof "C:/UwAmp/www/curso-angular/app/components/contacto.component"' is not assignable to type 'Type | ComponentDefinition'. Type 'typeof "C:/UwAmp/www/curso-angular/app/components/contacto.component"' is not assignable to type 'ComponentDefinition'. Property 'type' is missing in type 'typeof "C:/UwAmp/www/curso-angular/app/components/contacto.component"'.
這是我的代碼:
import {Component} from "angular2/core";
import {PeliculasListComponent} from "./components/peliculas-list.component";
import {PeliculasFooterComponent} from "./components/peliculas-footer.component";
import ContactoComponent from "./components/contacto.component";
import {ROUTER_DIRECTIVES, RouteConfig, Router} from "angular2/router";
@Component({
selector: "my-app",
templateUrl: "app/views/peliculas.html",
directives: [PeliculasListComponent,
PeliculasFooterComponent,
ContactoComponent,
ROUTER_DIRECTIVES]
})
@RouteConfig([
{path: "/peliculas", name:"Peliculas", component: PeliculasListComponent, useAsDefault: true},
{path: "/contacto", name:"Contacto", component: ContactoComponent}*/
])
export class AppComponent{
public titulo:string = "Peliculas con angular" ;
}
同比有什麼想法如何解決?謝謝!!
看起來你可能已經升級了你的angular 2版本,並且正在使用beta版本編寫一個項目。路由和指令(導入)現在屬於NgModule –
@JasonGoemaat只是爲了擴大你的觀點,這個應用程序是用舊版本編寫的,這個版本很難找到相關文檔,並且可能有一些未知的bug和問題。如果您剛剛開始,請在事情發生變化時升級到最新版本。如果你正在維護一個現有的應用程序,那麼上帝會幫助你。 –
我並不認爲這個過程是如此困難,如果您剛開始使用該項目,並且不熟悉測試版中的事情是如何完成的,那麼可能會更困難。你可以看看[NgModule文檔](https://angular.io/docs/ts/latest/guide/ngmodule.html)和[本指南](https://www.barbarianmeetscoding.com/blog/2016/ 08/13/updates-your-angular-2-app-from-rc4-to-rc5-a-practical-guide /),當他們引入NgModule時,從RC4更新到RC5。基本上創建新的NgModule並將組件的聲明移至它並更改引導。 –