我總是發現它非常有用,只需使用 ionic serve
檢查鉻中的元素,並很容易看到給定設備的樣式。
要訪問角度中的DOM元素,我使用了#id路由。以下片段用於驗證適當的類是否被離子應用。
HTML的home.html的
<ion-spinner #testspinner name="crescent" paused="{{isPaused}}"></ion-spinner>
TS- home.ts
import {Component} from '@angular/core';
import {ViewChild} from '@angular/core';
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
isPaused: boolean;
@ViewChild('testspinner') testspinner;
constructor() {
this.isPaused = false; // set to true will cause to never have animation state running.
}
containsPausedClass(list: string[]) {
return (list.indexOf('spinner-paused') != -1);
}
ngAfterViewInit() {
// if the spinner is allows to load without 'spinner-paused' then safari will work.
setTimeout(() => {
this.isPaused = true;
}, 0);
console.log('test spinner is paused ',
this.containsPausedClass(this.testspinner._elementRef.nativeElement.classList.value));
}
togglePause() {
this.isPaused = !this.isPaused;
setTimeout(() => {
console.log('test spinner is paused ',
this.containsPausedClass(this.testspinner._elementRef.nativeElement.classList.value));
}, 100);
}
}
你在哪裏把這個代碼? – Duannx