Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 2从主机获取类名作为输入,并应用于子元素_Angular - Fatal编程技术网

Angular 2从主机获取类名作为输入,并应用于子元素

Angular 2从主机获取类名作为输入,并应用于子元素,angular,Angular,在Angular 2组件中获取一个类名字符串并将其添加到其子级的最佳方法是什么?我还想检测字符串是否为空,或者是否没有使用该选项,并且没有添加该类 我的组件如下所示: @Component({ selector: "my-dropdown-toggle", template: ` <button <Input Class from the _classname variable here>> <ng-conte

在Angular 2组件中获取一个类名字符串并将其添加到其子级的最佳方法是什么?我还想检测字符串是否为空,或者是否没有使用该选项,并且没有添加该类

我的组件如下所示:

@Component({
    selector: "my-dropdown-toggle",
    template: `
        <button <Input Class from the _classname variable here>>
            <ng-content></ng-content>
            <i class="fa fa-arrow"></i>
        </button>
    `,
    host: {
        "[class.dropdown-toggle]" : "true"
    }
})
export class MyDropdownToggle {
  @Input() _classname: string;
  ...
}
<my-dropdown-toggle [_classname]="btn btn-danger">Hello</my-dropdown-toggle>
@组件({
选择器:“我的下拉开关”,
模板:`
`,
主持人:{
“[类.下拉切换]:“真”
}
})
导出类MyDropdownToggle{
@Input()_classname:string;
...
}
我想这样使用它:

@Component({
    selector: "my-dropdown-toggle",
    template: `
        <button <Input Class from the _classname variable here>>
            <ng-content></ng-content>
            <i class="fa fa-arrow"></i>
        </button>
    `,
    host: {
        "[class.dropdown-toggle]" : "true"
    }
})
export class MyDropdownToggle {
  @Input() _classname: string;
  ...
}
<my-dropdown-toggle [_classname]="btn btn-danger">Hello</my-dropdown-toggle>
你好