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