在Angular 5中,可以通过使用动态类名来传递给ng-content的"select"属性。下面是一个示例解决方案:
在父组件的模板中,使用属性绑定将动态类名传递给子组件:
然后,在子组件中,使用@Input装饰器来接收动态类名:
import { Component, Input } from '@angular/core';
@Component({
selector: 'app-child',
template: ' '
})
export class ChildComponent {
@Input() dynamicClass: string;
}
最后,在父组件中使用所需的动态类名:
Hello, World!
这样,父组件中的div元素将具有类名"myDynamicClass",并且将被传递给子组件的ng-content标签的"select"属性。