【问题标题】:How to make reference of the element in ionic如何引用离子中的元素
【发布时间】:2018-03-28 18:11:40
【问题描述】:

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

.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
    }

【问题讨论】:

标签: angular ionic-framework ionic2 ionic3 viewchild


【解决方案1】:

.html

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

解决问题!

【讨论】:

    【解决方案2】:

    从 'ionic-angular' 导入 { ActionSheetController };

    导出类 MyPage {

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

    }

    presentActionSheet() {

    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();
    

    }

    }

    【讨论】:

      猜你喜欢
      • 2015-03-27
      • 2019-07-17
      • 1970-01-01
      • 2021-11-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多