【问题标题】:Angular dart component init角飞镖组件初始化
【发布时间】:2014-10-10 14:22:57
【问题描述】:

有没有办法等待组件初始化?

@Component(
  selector: "my-component",
  templateUrl: 'component/my.html',
  useShadowDom: false,
  publishAs: "ctrl"
)
class MyComponent {

  @NgAttr('foo')
    String foo;
  }

  @NgAttr('bar')
    String bar;
  }

  MyComponent(){
    print(foo);
    print(bar);
  }
}

用法:

<my-component foo="bar" bar="baz"></my-component>

当我像这样使用组件时,构造函数会打印:null, null

我可以为 foo 和 bar 编写一个 setter,并检查每个 set 是否都已设置。但是如果没有提供任何值..我的 init 永远不会被解雇。

我是否必须实现一个提供 init 方法或其他东西的接口?

【问题讨论】:

    标签: dart components angular-dart


    【解决方案1】:

    和这里显示的一样Connecting 2 controllers and have access to the first controllers propertie in the second controller

    实现AttachAware 接口。在构造元素之前不能设置实例的值,因此在执行构造函数时没有机会从外部设置字段。

    【讨论】:

      【解决方案2】:

      正如 Günter 所说,实施 AttacheAware 或 !! ShadowRootAware。 onShadowRoot 出现在 onAttachAware 之后。它为您提供的参数(ShadowRoot)是您的自定义元素。该名称具有误导性 - 如果 useShadowDom 为 false,它也有效。

      【讨论】:

        猜你喜欢
        • 2017-11-26
        • 2022-11-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多