【问题标题】:Can I bind an attribute to web component?我可以将属性绑定到 Web 组件吗?
【发布时间】:2013-06-07 21:07:33
【问题描述】:

如果我有全局 @observable var myObservable = 'foo'; 我可以像这样将它传递给 Web 组件:

    <x-component my-attribute="{{myObservable}}"></x-component>

它在WebComponent.created() 生命周期方法之前传递给XComponent.myAttribute。问题是当我更改 myObservable = 'bar'; 时,XComponent.myAttribute 没有更改。

这种类型的绑定可能以某种方式实现吗?或者WebComponent.attributeChanged(...) 是这个的关键(当它由 Web UI 团队实现时)?

【问题讨论】:

    标签: dart dart-webui


    【解决方案1】:

    我相信您可以为此使用bind-

    试试这个:

    <x-component bind-my-attribute="myObservable"></x-component>
    

    另外,请记住也为my-attribute 指定@observable

    【讨论】:

    • bind--prefix 有效。谢谢!我没有从文档中找到它。仅绑定输入类型 HTML 元素。我想给你 +1,但我不能 - 需要 15 个声望 :(.
    • @jkorhonen,您可以按投票按钮下方的“接受回答”按钮(对勾)。
    猜你喜欢
    • 1970-01-01
    • 2012-07-23
    • 2010-10-29
    • 2018-05-10
    • 2012-12-11
    相关资源
    最近更新 更多