【问题标题】:Angular: HostBinding to custom component propertyAngular:HostBinding 到自定义组件属性
【发布时间】: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 上吗?

我已经看到很多绑定到父/主机上的classstyle属性 的示例,但没有任何自定义属性,除了提到它是可能的。 Angular 文档还声明 HostBinding takes an optional parameter that specifies the property name of the host element that will be updated.

有没有人可以分享这个工作的例子?

谢谢。

【问题讨论】:

    标签: angular


    【解决方案1】:

    看起来这可能是一个错误 - 尽管认为它被认为是按设计工作的。 https://github.com/angular/angular/issues/16797

    属性没有绑定,只有类。,attr。和风格。

    【讨论】:

      猜你喜欢
      • 2011-01-12
      • 1970-01-01
      • 2011-11-12
      • 2011-01-21
      • 2011-09-20
      • 2013-01-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多