How to add a spinner while loading the content in AngularJS?

后端 未结 7 2079
谎友^
谎友^ 2021-01-02 02:09

I am using button spinner while loading the content, when the user clicks on the \"Search\" button content will load, at this time buttonLabel will be changed t

7条回答
  •  梦谈多话
    2021-01-02 02:28

    For Angular2/4, you can use [hidden] to control the visibility of the spinner. Here is a Plunker.

    
    

    Where spinning is defined in as:

    
    

    And your component simply sets the boolean to control the visibility of the spinner. In this example, we simply spin for 10 seconds.

    import {Component} from 'angular2/core';
    import {Observable} from 'rxjs/Rx';
    
    @Component({
      selector: 'do-something',
      templateUrl: 'src/dosomething.html'
    })
    export class DoSomething {
       private spin: boolean = false;
    
       onClickDoSomething() {
         this.spin = true;
         this.sub = Observable.interval(10000).subscribe(x => {
             this.sub.unsubscribe();
             this.spin = false;
         }); 
       }
    }
    

提交回复
热议问题