IONIC4 : how to use cssClass for Loading , it is doesn't work

只谈情不闲聊 提交于 2019-12-18 09:48:09

问题


I want to change ion-loading style using cssClass ,my code as follow:

loading.page.ts :

@Component({
    selector: 'app-loading',
    templateUrl: './loading.page.html',
    styleUrls: ['./loading.page.scss'],
})
export class LoadingPage {

constructor(public lLoadingController: LoadingController) { }

async  presentCunstomLoading() {
    const loading = await this.lLoadingController.create({
        spinner: 'hide',
        duration: 500000,
        content: 'Please wait...',
        translucent: true,
        cssClass: 'custom-class'
    });
    return await loading.present();
}
}

loading.page.scss ::

`

app-loading {
  .custom-class {
    background: #e0b500;
  }

}`

loading.page.html :

<ion-content padding>
    <ion-button (click)="presentModal()">open modal</ion-button>
</ion-content>

What's problem with this? Anyone can help me . I am confused. Thanks advance.


回答1:


theme/variables.scss

ion-loading.custom-loading {
  .loading-wrapper {
    background: transparent;
    box-shadow: none;
  }
}

I don't know why, but it works in Ionic4.

If you write in loading.page.scss, it doesn't work.




回答2:


I'm Using IONIC 4.

this.myLoading = await this.loadingCtrl.create({ 
  spinner: null,
  message: '<ion-img src="assets/gif/loading.gif"></ion-img>',
  cssClass: 'custom-loading'
});
await this.myLoading.present();

at theme/variables.scss

ion-loading.custom-loading {
  .loading-wrapper {
    background: transparent !important;
    box-shadow: none !important;
  }
}

There you go. Now you have a custom loading with transparent background.




回答3:


Rano Paimin, your solution doesn't work, so I'll improve your answer:

I'm Using IONIC 4

this.myLoading = await this.loadingCtrl.create({ 
  spinner: null, -> here you can add others spinners ou set null 
  remove this attribute -> message: '<ion-img src="assets/gif/loading.gif"></ion-img>', 
  cssClass: 'custom-loading'
});
await this.myLoading.present();

at theme/variables.scss

ion-loading.custom-loading {
  .loading-wrapper {
    background: #ffffff url("assets/gif/loading.gif") no-repeat center;
  }
}

If you want change dimensions you can change these properties:

  background-size: 100px 100px; /* to change dimension of background */
  padding-top: 36px; /* padding top of white square */
  padding-bottom: 36px; /* padding bottom of white square */
  border-radius: 0.8rem; /* border-radius white square */

I hope that helps you.



来源:https://stackoverflow.com/questions/52107686/ionic4-how-to-use-cssclass-for-loading-it-is-doesnt-work

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!