【发布时间】:2018-05-22 07:42:43
【问题描述】:
我正在尝试从子组件绑定到父组件上的属性,但它不起作用。代码如下:
家长
myProp: string;(我也试过@Input() myProp: string;)
儿童
@HostBinding('myProp') prop1: string;
我得到的错误是 Can't bind to 'myProp' because it is not an known property of 'child-component' 这是有道理的,因为 HostBinding 背后的想法不是应该在 parent 上查找属性,而不是在 child 上吗?
我已经看到很多绑定到父/主机上的class、style 和属性 的示例,但没有任何自定义属性,除了提到它是可能的。 Angular 文档还声明 HostBinding takes an optional parameter that specifies the property name of the host element that will be updated.
有没有人可以分享这个工作的例子?
谢谢。
【问题讨论】:
标签: angular