如何计算ion-select Childs(ion-option)?
How to count the ion-select Childs (ion-option)?
在ion-select?
里面可以算出ion-option
<ion-select>
<ion-option></ion-option>
<ion-option></ion-option>
<ion-option></ion-option>
</ion-select>
console.log(something)
我会得到 3 个 ?
谢谢。
类似
@ViewChildren('ion-option')
ionOptions: QueryList<any>;
然后是
ionOptions.length;
[编辑]
抱歉我最后的回答是错误的。
如果不想使用 document.getElementById('mySelect')
,也可以使用 Viewchild 访问 dom 元素
所以 ViewChild 的解决方案
myPage.html
<ion-select #mySelect>
<ion-option>Bacon</ion-option>
<ion-option>Black Olives</ion-option>
<ion-option>Extra Cheese</ion-option>
<ion-option>Mushrooms</ion-option>
<ion-option>Pepperoni</ion-option>
<ion-option>Sausage</ion-option>
</ion-select>
首先在你的组件中使用它:
import { Component,ViewChild } from '@angular/core';
然后声明你的变量:
@ViewChild('mySelect') selectDom;
ionViewDidLoad(){
console.log(this.selectDom._options.length); // = 6 in my case
}
在ion-select?
里面可以算出ion-option<ion-select>
<ion-option></ion-option>
<ion-option></ion-option>
<ion-option></ion-option>
</ion-select>
console.log(something)
我会得到 3 个 ?
谢谢。
类似
@ViewChildren('ion-option')
ionOptions: QueryList<any>;
然后是
ionOptions.length;
[编辑] 抱歉我最后的回答是错误的。
如果不想使用 document.getElementById('mySelect')
,也可以使用 Viewchild 访问 dom 元素所以 ViewChild 的解决方案
myPage.html
<ion-select #mySelect>
<ion-option>Bacon</ion-option>
<ion-option>Black Olives</ion-option>
<ion-option>Extra Cheese</ion-option>
<ion-option>Mushrooms</ion-option>
<ion-option>Pepperoni</ion-option>
<ion-option>Sausage</ion-option>
</ion-select>
首先在你的组件中使用它:
import { Component,ViewChild } from '@angular/core';
然后声明你的变量:
@ViewChild('mySelect') selectDom;
ionViewDidLoad(){
console.log(this.selectDom._options.length); // = 6 in my case
}