在另一个指令的主机中使用指令
Use directive in host of another Directive
我想通过使用主机 属性 向另一个指令中的元素添加一个指令,但似乎没有办法引用另一个指令。
@Directive({
selector: '[one]',
host: { '[two]': '"some-value"' }
// How can I reference DirectiveTwo here?
})
export class DirectiveOne { }
@Directive({
selector: '[two]'
})
export class DirectiveTwo { }
执行此操作时,出现标准 "Can't bind to 'two' since it isn't a known native property" 错误。
从一个指令引用和使用另一个指令的正确方法是什么?
指令由 Angular 实例化,仅用于匹配静态添加的 HTML(元素、id、属性、class、...)的选择器。
无法使用 @Component()
或 @Directive()
装饰器的 host
参数实例化指令。也无法使用 ViewContainerRef.createComponent()
(以前的 DynamicComponentLoader
)
动态创建指令
获取对由 Angular 实例化的另一个指令的引用,因为在同一元素上静态添加 HTML 是受支持的。
我想通过使用主机 属性 向另一个指令中的元素添加一个指令,但似乎没有办法引用另一个指令。
@Directive({
selector: '[one]',
host: { '[two]': '"some-value"' }
// How can I reference DirectiveTwo here?
})
export class DirectiveOne { }
@Directive({
selector: '[two]'
})
export class DirectiveTwo { }
执行此操作时,出现标准 "Can't bind to 'two' since it isn't a known native property" 错误。
从一个指令引用和使用另一个指令的正确方法是什么?
指令由 Angular 实例化,仅用于匹配静态添加的 HTML(元素、id、属性、class、...)的选择器。
无法使用 @Component()
或 @Directive()
装饰器的 host
参数实例化指令。也无法使用 ViewContainerRef.createComponent()
(以前的 DynamicComponentLoader
)
获取对由 Angular 实例化的另一个指令的引用,因为在同一元素上静态添加 HTML 是受支持的。