angular代码片段

<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;
      }
    }
  }

【展开一项的折叠面板】

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。