简体   繁体   English

角指令@hostbinding参数

[英]Angular directive @hostbinding argument

Having trouble understanding something regarding the @Hostbinding argument: 无法理解有关@Hostbinding参数的某些信息:

Code: 码:

import { Directive, HostBinding } from "@angular/core";

@Directive({
    selector: '[appDropdown]'
})
export class DropdownDirective {
    @HostBinding('class.open') isOpen = false;

}

Why is the argument in the @Hostbinding() passed in as class.open ? 为什么@Hostbinding()的参数作为class.open It looks like the class is an object or something. 看来该类是一个对象或东西。

Grab an element and log it to the console like so: 抓取一个元素并将其记录到控制台,如下所示:

console.log($('div'));

In the console you'll see that that element is like an object, it has fields and methods. 在控制台中,您将看到该元素就像一个对象,它具有字段和方法。 You could even go further and log the following to the console: 您甚至可以走得更远,然后将以下内容记录到控制台:

console.log($("div").attributes.class.value);

and you will see the class displayed in the console. 您将看到控制台中显示的类。

In your case "class.open" means that that element must likely has more than one class. 在您的情况下,“ class.open”表示该元素可能必须具有多个类。

You can also see it like this: 您也可以这样看:

Element: {
     attributes : {
                  class : {
                        "open", etc... 
                  }
               }
}

I hope it helps you see what's happening there. 我希望它可以帮助您了解那里发生了什么。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM