我是sharepoint SPFX的新手,因为我正在使用angular js 5,所以我想在模板组件中显示一个由Promise返回的简单数字数组:
@Component({
selector: 'app-root',
templateUrl: './app.component.html'
})
export class AppComponent implements OnInit {
promise: Promise<number[]>;
public array: Array<number>;
ngOnInit() {
this.promise = new Promise((resolve, reject) => {
resolve([1, 2, 3, 4, 5, 6]);
});
this.promise.then((data: Array<number>) => {
this.array = data;
});
}
}
in app.component.html :
<p *ngIf="!array">Waiting for values</p><p *ngFor="let a of array">{{a}}</p>
该数组始终是未定义的,对您的帮助和感谢都感谢