SPFX和angular5:如何在模板中获取Promise值

时间:2018-08-29 08:24:51

标签: angular5 spfx

我是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>

该数组始终是未定义的,对您的帮助和感谢都感谢

0 个答案:

没有答案