1

我想查看离子卡的元素参考,但看不到。下面是我的代码。

.html

<ion-content>
<ion-card *ngFor="let card of cards" #card>
</ion-card>
</ion-content>

.ts

//all imports are made
//class defined

@ViewChild("card", {read: ElementRef}) card: ElementRef;

constructor(private elementRef: ElementRef){}

ngAfterViewInit(): void {
        console.log('card' -->, this.card); // in the console it displays undefined
    }
4

2 回答 2

1

.html

<ion-content>
<section #card>
<ion-card *ngFor="let card of cards">
</ion-card>
</section>
</ion-content>

解决问题!

于 2018-03-28T09:37:15.610 回答
-1

从“离子角”导入 { ActionSheetController };

导出类 MyPage {

构造函数(公共 actionSheetCtrl:ActionSheetController){

}

呈现动作表(){

let actionSheet = this.actionSheetCtrl.create({

  title: 'Modify your album',

  buttons: [

    {

      text: 'Destructive',

      role: 'destructive',

      handler: () => {

        console.log('Destructive clicked');

      }

    },{

      text: 'Archive',

      handler: () => {

        console.log('Archive clicked');

      }

    },{

      text: 'Cancel',

      role: 'cancel',

      handler: () => {

        console.log('Cancel clicked');

      }

    }

  ]

});

actionSheet.present();

}

}

于 2018-03-28T10:11:40.480 回答