DEV Community

Faisal Ahmed
Faisal Ahmed

Posted on

Ionic loader, without clicking event (loading.dismiss())

In html file,

  <div *ngIf="!isLoading" class="edit-area">
    <div class="container">
      <div class="user">
            <h2>Show This Content</h2>
      </div>
    </div>
  </div>
Enter fullscreen mode Exit fullscreen mode

In ts file

// data store
isLoading = false;

  constructor(
    private loadingCtrl: LoadingController,
  ) { }


  ngOnInit() {
    this.onInitForm();
    // Base Data
    this.getLoggedUserData();
    this.toggleLoading();
  }

  // loading
  async toggleLoading() {
    if (this.isLoading) {
      await this.showLoading();
    }
  }

  async showLoading() {
    const loading = await this.loadingCtrl.create({
      message: 'Loading.....',
      duration: 3000,
    });

    await loading.present();
    loading.dismiss();
    this.isLoading = false;
  }


/***
   * HTTP REQUEST HANDLE
   * getLoggedUserData()
   */
  private getLoggedUserData() {
    this.isLoading = true;
    if (this.isLoading) {
      this.showLoading();
    }
    this.subDataOne = this.userDataService.getLoggedInUserData().subscribe({
      next: (res) => {
        this.user = res.data;
        console.log('this.user', this.user)
        this.setFormValue();
        // this.isLoading = false;
      },
      error: (err) => {
        if (err) {
          console.log(err);
        }
      }
    })
  }


Enter fullscreen mode Exit fullscreen mode

Speedy emails, satisfied customers

Postmark Image

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay