zoukankan      html  css  js  c++  java
  • 【angular7】防抖、节流

    ...
    import { Subject } from 'rxjs';
    import { tap, catchError, debounceTime, distinctUntilChanged } from 'rxjs/operators';
    
    ...
    
    export class demoComponent implements OnInit {
        //状态
        codeSearch: boolean = false;
    
        searchText: Subject<string> = new Subject<string>();
      // 事件调用
        searchCode(keyword: string): any {
            this.searchText.next(keyword);
        }
      //调用接口获取数据
        getCode(keyword: string): any {
            if (keyword === '') return;
            this.codeSearch = true;
            this.http.get(ApiUrl)
                .pipe(tap(() => {this.codeSearch = false;}))
                .subscribe((res: any) => {
                    console.log(res)
                    if (res.code == 200) {
                        this.strategyList = res.data;
                        this.cdr.detectChanges();
                        if (res.data.length == 0) {
                            this.msg.error('未查询到');
                        }
                    } else {
                        this.msg.error('获取数据出错');
                    }
                });
        }
    
        constructor() { }
    
        ngOnInit() {
            this.searchText
                .pipe(debounceTime(300))
                .pipe(distinctUntilChanged())
                .subscribe(string => {
                    this.getCode(string);
                });
        }
    }
    

      

  • 相关阅读:
    Spring的AOP与代理
    JAVA 反射机制
    JDK动态代理与Cglib库
    HDFS的运行原理(转)
    Spring中IoC的入门实例
    spring
    Spring中IOC和AOP的详细解释
    自己动手写ORM
    Mongodb 安装
    mongodb集群配置分片集群
  • 原文地址:https://www.cnblogs.com/dustinsky/p/12167206.html
Copyright © 2011-2022 走看看