【问题标题】:Is there something similar to angular $rootScope in Polymer.dart?Polymer.dart 中是否有类似于 angular $rootScope 的东西?
【发布时间】:2015-07-01 18:23:19
【问题描述】:

我知道在 Angular 中存在一个叫做 $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 的角度来做。

【问题讨论】:

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


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-12-04
    • 2011-01-07
    • 1970-01-01
    • 2021-09-15
    • 2016-08-10
    • 1970-01-01
    • 2011-05-01
    • 1970-01-01
    相关资源
    最近更新 更多