在异步函数内部调用订阅函数不会绑定数据吗?

时间:2019-10-01 23:15:07

标签: angular ionic-framework

在Alertcontroller处理程序内,我想从API接收一些数据并将数据绑定到HTML页面中。但要等到单击页面后才能执行。 这是我的代码。

export class UserPage implements OnInit {
  dataPage: any;
  ngOnInit() {}
  constructor(userService: UserService) {}

  async alertFunction() {
    const alert = await this.alertController.create({
      header: 'Get data',
      message: 'Getting  data',
      buttons: [{
        text: 'get',
        handler: (blah) => {
          this.userService.getData().subscribe(r => {
            this.dataPage = r;
          });
        }
      }]
    });
    await alert.present();
  }

我正在通过{{dataPage}}用HTML显示此dataPage,但它不起作用。

0 个答案:

没有答案