将自定义指令绑定到主机 [英] Bind custom directive to host

查看:67
本文介绍了将自定义指令绑定到主机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看得很远,但似乎找不到答案.我创建了一个指令,该指令可以正常工作,但是我想将其动态绑定到组件的主机.

I've looked far and wide but I can't seem to find an answer. I've created a directive, which works fine, but I want to bind it to the host of a component dynamically.

示例:

@Directive({ selector: 'myDirective' })

@Component({ selector: 'myComponent',
    template: 'some content goes here...'
})
export class MyComponent {
    /* bind myDirective to host */
}

//when using myComponent, it should be
<myComponent></myComponent>
//not
<myComponent myDirective></myComponent>

我基本上想消除以下需要:a)显式设置myDirective和b)用一个元素包装模板,以仅使用myDirective

I basically want to remove the need to either a) explicitly set myDirective and b) wrap the template with an element just to use myDirective

推荐答案

当前不支持此功能.

另请参见 https://github.com/angular/angular/issues/8785

这篇关于将自定义指令绑定到主机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆