Angular 2快速入门教程问题(嵌套组件)

时间:2016-12-23 22:16:05

标签: javascript node.js angular typescript mean-stack

嘿大家我在快速入门教程之后学习Angular 2,但是我使用的是从newboston下载的模板,因为它配置为将typescript转换为java脚本,简而言之我的问题是当我尝试嵌套herodetail组件,它甚至不会在点击列表时显示,也不会导致chrome控制台中的任何错误。这是我的文件我知道有很多,但我不确定我是否犯了一个容易识别的错误。

的package.json

7fdfaa9c9c0931f52d9ebf2538bc99700f2e771f3af1c1d93945c2256c11aedd

tsconfig.json:

{
  "name": "angular-2",
  "version": "1.0.0",
  "scripts": {
    "start": "concurrently \"npm run tsc:w\" \"npm run lite\" ",
    "tsc": "tsc",
    "tsc:w": "tsc -w",
    "lite": "lite-server",
    "typings": "typings",
    "postinstall": "typings install"
  },
  "license": "ISC",
  "dependencies": {
    "angular2": "2.0.0-beta.21",
    "systemjs": "0.19.41",
    "es6-shim": "^0.35.0",
    "reflect-metadata": "0.1.9",
    "rxjs": "5.0.0-beta.6",
    "zone.js": "0.7.4"
  },
  "devDependencies": {
    "concurrently": "^3.1.0",
    "lite-server": "^2.1.0",
    "typescript": "^2.1.4",
    "typings": "^2.1.0"
  }
}

main.ts:

  "compilerOptions": {
    "types" : []
    "target": "es5",
    "module": "system",
    "moduleResolution": "node",
    "outDir": "app/js",
    "sourceMap": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "removeComments": false,
    "noImplicitAny": false
  },
  "exclude": [
    "node_modules",
    "typings/main",
    "typings/main.d.ts"
  ]
}

hero.ts

    /*import {bootstrap}    from 'angular/platform/browser';
import {AppComponent} from './app.component';

bootstrap(AppComponent);
 */
 import { platformBrowserDynamic } from '@angular2/platform-browser-dynamic';
import { AppModule } from './app.module';

platformBrowserDynamic().bootstrapModule(AppModule);
bootstrap(AppComponent);

英雄detail.component.ts

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

app.module.ts

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

@Component({
  selector: 'my-hero-detail',
  template: `
  <div *ngIf="hero">
    <h2>{{hero.name}} details!</h2>
    <div><label>id: </label>{{hero.id}}</div>
    <div>
      <label>name: </label>
      <input [(ngModel)]="hero.name" placeholder="name"/>
    </div>
  </div>
`

})
export class HeroDetailComponent {
  @Input()
  hero:Hero;

}

app.module.ts

    import { NgModule }      from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule }   from '@angular/forms';
import { AppComponent }  from './app.component';
import { HeroDetailComponent } from './hero-detail.component';
@NgModule({
  imports: [
    BrowserModule,
    FormsModule
  ],
  declarations: [
    AppComponent,
    HeroDetailComponent
  ],
  bootstrap: [ AppComponent ]
})
export class AppModule { }

0 个答案:

没有答案