如何理解angular ng类和dynamic类

如何理解angular ng类和dynamic类,angular,ng-class,Angular,Ng Class,我尝试使用ng类,我需要在angular中创建动态类。但是找不到一些简单明了的教程或者类似的东西 例如,我有这样的东西: app.template.html <div class="items-container" > <ul> <li class="item" *ngFor="let tag of tags"> <div class="icon" ng-mouseenter="mouseEnter(tag

我尝试使用ng类,我需要在angular中创建动态类。但是找不到一些简单明了的教程或者类似的东西

例如,我有这样的东西: app.template.html

<div class="items-container" >
    <ul>
        <li class="item" *ngFor="let tag of tags">
            <div class="icon" ng-mouseenter="mouseEnter(tag.name)">
                <img src="/assets/{{tag.icon}}" />
            </div>
            <div ngClass="{'show' : false, 'hide' : true, 'tag-name'}">
                {{tag.name}}
            </div>
        </li>
    </ul>

</div>

我希望在div.icon上鼠标输入后,同级div(.tagname)将类从hide更改为show。我真的不知道如何将变化的类与函数mouseEnter联系起来

在底座中,其工作原理如下:

  • 您创建了一些类(css/scss)
  • 您可以根据某些条件动态地将该类绑定到html元素
示例

isBlack=true
div.my-dynamic-class{
背景色:#000000;
}

您正在角度模板中使用AngularJS指令(ng mouseenter)。这不可能奏效。以下是NgClass的使用示例:。这里有更多的解释:。我在angular.io(angular的官方文档)中搜索NgClass就发现了这一切。非常感谢,这正是我所需要的。我错过了什么。@Eva任何时候;)
export class AGmainMenu {

    tags = mainMenuItems[0].tags;
    itemShow: false;

    mouseEnter(tag){
        console.log("mouse enter : ", this, tag);
    }
}