美文网首页
angular代码片段

angular代码片段

作者: luckyvip | 来源:发表于2020-06-08 14:22 被阅读0次
    <nz-tab *ngFor="let i of tabs" [nzTitle]="i.tab" (nzClick)="to(i)"></nz-tab>
    to(item: any) {
        this.router.navigateByUrl(`/pro/account/center/${item.key}`);
      }
    

    【tab路由传参】

    <input
                *ngIf="taging"
                #tagInput
                nz-input
                [(ngModel)]="tagValue"
                (blur)="tagBlur()"
                (keydown)="tagEnter($event)"
                nzSize="small"
                type="text"
     /> 
    
      tagEnter(e: KeyboardEvent) {
        // tslint:disable-next-line: deprecation
        if (e.keyCode === 13) {
          this.tagBlur();
        }
      }      
    
    【login enter登录】
    
    interval$: any;
    
    this.interval$ = setInterval(() => {
          this.count -= 1;
          if (this.count <= 0) {
            clearInterval(this.interval$);
          }
    }, 1000);
    
    ngOnDestroy(): void {
        if (this.interval$) {
          clearInterval(this.interval$);
        }
    }
    

    【定时器间隔调用以及清除】

    import {ElementRef} from '@angular/core';
    
     constructor(
        private randomUserService: RandomUserService,
        private elementRef: ElementRef
      ) {
      }
    
    copyDetail() {
        const copyEl = this.elementRef.nativeElement.querySelector('#test');
        const range = document.createRange();
        range.selectNode(copyEl);
        window.getSelection().removeAllRanges();
        window.getSelection().addRange(range);
        document.execCommand('copy');
        alert('复制成功!');
      }
    

    【angular操作dom一键复制功能】

    <ul nz-menu nzTheme="dark" nzMode="inline">
                <li nz-submenu nzTitle="User" nzIcon="user" [(nzOpen)]="openMap.sub1" (nzOpenChange)="openHandler('sub1')">
                    <ul>
                        <li nz-menu-item>Tom</li>
                        <li nz-menu-item>Bill</li>
                        <li nz-menu-item>Alex</li>
                    </ul>
                </li>
                <li nz-submenu nzTitle="Team" nzIcon="team" [(nzOpen)]="openMap.sub2" (nzOpenChange)="openHandler('sub2')">
                    <ul>
                        <li nz-menu-item>Team 1</li>
                        <li nz-menu-item>Team 2</li>
                    </ul>
                </li>
                <li nz-submenu nzTitle="home" nzIcon="team" [(nzOpen)]="openMap.sub3" (nzOpenChange)="openHandler('sub3')">
                    <ul>
                        <li nz-menu-item>Team 1</li>
                        <li nz-menu-item>Team 2</li>
                    </ul>
                </li>
    </ul>
    openMap: { [name: string]: boolean } = {
        sub1: true,
        sub2: false,
        sub3: false
      };
     openHandler(value: string): void {
        for (const key in this.openMap) {
          console.log(key);
          if (key !== value) {
            this.openMap[key] = false;
          }
        }
      }
    

    【展开一项的折叠面板】

    相关文章

      网友评论

          本文标题:angular代码片段

          本文链接:https://www.haomeiwen.com/subject/uktzzhtx.html