angular 2 - 英雄之旅 - 意外令牌] - polyfills 库
angular 2 - tour of heroes - Unexpected token ] - polyfills library
export class Hero {
id: number;
name: string;
}
import {Component, OnInit} from 'angular2/core';
import {Hero} from './hero';
import {HeroDetailComponent} from './hero-detail.component';
import {HeroService} from './hero.service';
@Component({
selector: 'my-app',
template: `
<h1>{{title}}</h1>
<h2>My Heroes</h2>
<ul class="heroes">
<li *ngFor="#hero of heroes" (click)="onSelect(hero)" [class.selected]="hero === selectedHero">
<span class="badge">{{hero.id}}</span> {{hero.name}}
</li>
</ul>
<my-hero-detail [hero]="selectedHero"></my-hero-detail>
`,
styles: [
`
.selected { color: green; }
`
],
directives: [HeroDetailComponent],
providers: [HeroService],
})
export class AppComponent implements OnInit {
public title = 'Tour of heroes';
public heroes = Hero[];
public selectedHero: Hero;
constructor(private _heroService: HeroService) {}
ngOnInit() {
this.getHeroes();
}
getHeroes() {
this.heroes = this._heroService.getHeroes().then( heroes => this.heroes = heroes );
}
onSelect(hero: Hero) {
this.selectedHero = hero;
}
}
我在 Angular 2 Typescript 介绍教程中看到过类似的问题,但不完全是这个...
Error: SyntaxError: Unexpected token ](…) (angular2-polyfills.js.332)
已尝试更改 index.html 中的 System.config 的建议,但这些建议不起作用。
虽然我的编辑器在线上出现红色下划线;
heroes = Hero[];
将其更改为;
heroes = [];
修复了错误,但由于未初始化为数组而给了我另一个错误。我是打字稿的新手,所以可能是一个简单的语法问题。
感谢任何帮助!
这是您使用的代码
export class AppComponent implements OnInit {
public title = 'Tour of heroes';
**public heroes = Hero[];**
public selectedHero: Hero;
constructor(private _heroService: HeroService) {}
ngOnInit() {
this.getHeroes();
}
getHeroes() {
this.heroes = this._heroService.getHeroes().then( heroes => this.heroes = heroes );
}
onSelect(hero: Hero) {
this.selectedHero = hero;
}
}
这里应该使用被屏蔽的代码作为
public heroes : Hero[];
export class Hero {
id: number;
name: string;
}
import {Component, OnInit} from 'angular2/core';
import {Hero} from './hero';
import {HeroDetailComponent} from './hero-detail.component';
import {HeroService} from './hero.service';
@Component({
selector: 'my-app',
template: `
<h1>{{title}}</h1>
<h2>My Heroes</h2>
<ul class="heroes">
<li *ngFor="#hero of heroes" (click)="onSelect(hero)" [class.selected]="hero === selectedHero">
<span class="badge">{{hero.id}}</span> {{hero.name}}
</li>
</ul>
<my-hero-detail [hero]="selectedHero"></my-hero-detail>
`,
styles: [
`
.selected { color: green; }
`
],
directives: [HeroDetailComponent],
providers: [HeroService],
})
export class AppComponent implements OnInit {
public title = 'Tour of heroes';
public heroes = Hero[];
public selectedHero: Hero;
constructor(private _heroService: HeroService) {}
ngOnInit() {
this.getHeroes();
}
getHeroes() {
this.heroes = this._heroService.getHeroes().then( heroes => this.heroes = heroes );
}
onSelect(hero: Hero) {
this.selectedHero = hero;
}
}
我在 Angular 2 Typescript 介绍教程中看到过类似的问题,但不完全是这个...
Error: SyntaxError: Unexpected token ](…) (angular2-polyfills.js.332)
已尝试更改 index.html 中的 System.config 的建议,但这些建议不起作用。
虽然我的编辑器在线上出现红色下划线;
heroes = Hero[];
将其更改为;
heroes = [];
修复了错误,但由于未初始化为数组而给了我另一个错误。我是打字稿的新手,所以可能是一个简单的语法问题。
感谢任何帮助!
这是您使用的代码
export class AppComponent implements OnInit {
public title = 'Tour of heroes';
**public heroes = Hero[];**
public selectedHero: Hero;
constructor(private _heroService: HeroService) {}
ngOnInit() {
this.getHeroes();
}
getHeroes() {
this.heroes = this._heroService.getHeroes().then( heroes => this.heroes = heroes );
}
onSelect(hero: Hero) {
this.selectedHero = hero;
}
}
这里应该使用被屏蔽的代码作为
public heroes : Hero[];