我似乎无法将 this.heroes 中的数据显示在列表中。我放了一个警告(this.heroes [0] .name); ,它确实显示了数据,所以 this._service.getHeroes(); 正在返回数据
app.html
<div style="width:1000px;margin:auto">
<ul>
<li *ngFor="#hero of heroes">
<span>{{hero.name}}</span>
</li>
</ul>
</div>
app.component.ts
import {Component} from 'angular2/core';
import {RouteConfig, ROUTER_DIRECTIVES} from 'angular2/router';
import {HeroService} from './heroes/hero.service';
import {Hero} from './heroes/hero';
@Component({
selector: 'my-app',
templateUrl: 'templates/app.html',
providers: [HeroService],
directives: [ROUTER_DIRECTIVES]
})
export class AppComponent {
heroes: Hero[];
constructor(private _service: HeroService) { }
ngOnInit() {
this.heroes = this._service.getHeroes();
}
}
答案 0 :(得分:1)
首先尝试一下,看看它是否有效:
(https?:\/\/)?(w{3}\.)?\bfacebook\.com\/[^\/.]*\.\S*
如果这样可行,你可能有一个不支持* ngFor语法的旧版角度版本(我认为在新版本的角度2中支持这一点)。
答案 1 :(得分:0)
我做了一些研究,没有数据显示。例如:
<h2>My favorite hero is {{ myHero }}</h2>
得到一个空行(myHero是一个填充的字符串),而
<h2>My favorite hero is </h2>
显示器
我最喜欢的英雄是
我要更改Angular 2的Beta版本以查看它是否有帮助