Polymer.dart中有类似angular $ rootScope的东西吗?

时间:2015-07-01 18:23:20

标签: angularjs dart polymer dart-polymer angularjs-rootscope

我知道在角度存在称为$ rootScope的东西。这个包含将由所有控制器共享的变量。我正在为Polymer寻找类似的东西,所以我不需要总是将父变量作为属性传递。

现在我正在做类似的事情:

索引HTML代码:

<body>
  <my-parent-component some-attribute="hello"></my-parent-component>
</body>

父html代码:

<my-parent-component>
  <template>
    <p>someAttribuet could be used by parent: {{someAttribute}}</p>
    <my-child-component some-attribute="{{someAttribute}}"></my-child>
  </template>
</my-parent-component>

父母飞镖代码:

class MyParentComponent extends PolymerElement {
  @published var someAttribute;
}

子HTML代码:

<my-child-component>
  <template>
    <p>some Attribute used here: {{someAttribute}}</p>
  </template>
</my-child-component>

儿童飞镖码:

class MyChildComponent extends PolymerElement {
  @published var someAttribute;
}

换句话说,我将属性从顶级父级一直传递到最低级别的子级。我认为这不好,我想用类似$ rootScope的角色来做。

1 个答案:

答案 0 :(得分:3)

Polymer没有根范围。在Polymer中,您可以在表达式中引用元素以及父元素或子元素。更通用的解决方案是全局变量或全局元素,如此处所解释的https://stackoverflow.com/a/29864797/217408