angular - 我不能在 Angular 6 的箭头上使用 Ngif

标签 angular arrows angular-ng-if

这是我的 html 文件:

<div class="site"><a routerLink="site" (click)="myMove()"  class="text">
  <mat-icon svgIcon="site" class="icon"><span  class="fa fa-caret-right caret1"  *ngIf="text2"></span>
    <div *ngIf="text" class="text1">Site</div>
  </mat-icon>
</a></div>

这是我的 CSS 文件:

.text {
  margin: 0px 0px 0px 40px;
}
.caret1 {
  margin-left: 30px;
  position: absolute;
}

这是我的 typescript 文件:

export class GeneralManagementComponent implements OnInit {

  text = true;
  text2 = false;
   constructor() {
   }

   ngOnInit() {
   }

  public myMove() {
  this.text2 = true;
  this.text = false;
  }
 }

我想要做什么当我点击链接时,显示箭头,当我使用ngif时,它不适用于箭头。但是当我将 ngif 用于另一个 div 时,它就起作用了。 我不知道为什么我不能使用 ngif 作为箭头

我在这里提出我的问题https://stackblitz.com/edit/angular-slmxmk?file=src%2Fapp%2Fapp.component.html

我使用 Angular 6。

最佳答案

组件.ts:

import { Component } from '@angular/core';
import {MatIconRegistry} from '@angular/material/icon';
import {DomSanitizer} from '@angular/platform-browser';

@Component({
  selector: 'my-app',
  templateUrl: './app.component.html',
  styleUrls: [ './app.component.css' ]
})
export class AppComponent  {
  text = true;
  constructor(
  private matIconRegistry: MatIconRegistry,
  private domSanitizer: DomSanitizer
  ){
        this.matIconRegistry.addSvgIcon(
      'site',
      this.domSanitizer.bypassSecurityTrustResourceUrl('../assets/icons/web.svg')
    );  
  }
    public myMove() {
    this.text = !this.text;
  }
}

html

<a (click)="myMove()" class="text">
  <mat-icon *ngIf="!text" svgIcon="site" class="icon">
    <span  class="divstyle1" >&#x27A4;</span>
    </mat-icon>
    <mat-icon *ngIf="text" svgIcon="site" class="icon">
    <div  class="text1">Site</div>
  </mat-icon>
</a>

链接: blitz

关于angular - 我不能在 Angular 6 的箭头上使用 Ngif,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53301127/

相关文章:

angular - ngIf 和 formcontrol.touched 不工作

javascript - 如何修补 formArray 中的值

Angular 2 试图在服务中实现 Observables

angular - 如何将窗口注入(inject) Angular 2.1.0

angular - Angular 模块之间的路由

haskell - 如何定义多变量箭头?

angularjs - 如何让 ng-model 在 ng-if 中工作?

haskell - profunctors和箭头有什么关系?

f# - 你能在 F# 中定义一个运算符 (***) 吗?

javascript - AngularJS 更新表单并选择菜单选项?