2017-09-28 3 views
2

私は角度のウェブサイトにあるチュートリアルを試しています。私はつまずくと私は問題を把握することはできません。角4サンプルのチュートリアルタイプのスクリプトエラー

私はangle cliを使ってプロジェクトを作成しました。

app.component.ts

import { Component } from '@angular/core'; 
import {Hero} from './hero'; 



const HEROES: Hero[] = [ 
    { id: 11, name: 'Mr. Nice' }, 
    { id: 12, name: 'Narco' }, 
    { id: 13, name: 'Bombasto' }, 
    { id: 14, name: 'Celeritas' }, 
    { id: 15, name: 'Magneta' }, 
    { id: 16, name: 'RubberMan' }, 
    { id: 17, name: 'Dynama' }, 
    { id: 18, name: 'Dr IQ' }, 
    { id: 19, name: 'Magma' }, 
    { id: 20, name: 'Tornado' } 
]; 


@Component({ 
    selector: 'app-my-app', 
    templateUrl: './app.component.html', 
    styleUrls: ['./app.component.css'] 
}) 
export class AppComponent { 
    title = 'app'; 
    selectedHero: Hero; 
    heroes = HEROES; 
    onSelect(hero: Hero): void { 
    this.selectedHero = hero; 
    } 
} 

app.module.ts

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

import { AppComponent } from './app.component'; 
import {HeroDetailComponent} from './hero-detail.component'; 

@NgModule({ 
    declarations: [ 
    AppComponent, 
    HeroDetailComponent 
    ], 
    imports: [ 
    BrowserModule, 
    FormsModule 
    ], 
    providers: [], 
    bootstrap: [AppComponent] 
}) 
export class AppModule { } 

主人公-detail.component.ts

import {Component, Input} from '@angular/core'; 
import {Hero} from './hero'; 
@Component({ 
selector: 'app-hero-detail', 
templateUrl: './hero-detail.component.html' 
}) 
export class HeroDetailComponent { 
@Input() hero: Hero; 
} 

hero.ts

export class Hero { 
id: number; 
name: string; 
} 

Srcの構造:

enter image description here

TSエラー以下のアプリ

の起動時に取得

コンパイルに失敗しました。

/Users/name/Documents/workspaces/angular-tutorial1/firstapp/src/app/hero-detail.component.ts (3,12): '{セレクタ:番号; templateUrl:文字列; } ' は、'コンポーネント 'タイプのパラメータに割り当てられません。タイプ ' 'セレクタ 'は互換性がありません。 タイプ 'number'はタイプ 'string'に割り当てられません。

+0

hero-detail.componentのjsファイルを貼り付けてみてください。 – kriss

+0

hero-detail.component.htmlファイルを追加できますか? –

+0

これは 'selector: 'app-hero-detail''が明らかに数字ではないという不思議なバグです。私の推測ではあなたのキャッシュはきれいではありません。あなたのIDEを閉じ、node_modules、 'npm cache clean'、' npm install'を削除してください。必要なその他の情報は、 ''とヒーロー詳細html自体があるHTMLです。 –

答えて

0

app-component.htmlのような行がありますか?

<app-hero-detail [hero]="selectedHero"></app-hero-detail>