angularjs - 在Polymer.dart中是否有类似于angular $ rootScope的东西?

标签 angularjs dart polymer dart-polymer angularjs-rootscope

我知道在angular中存在一个称为$ rootScope的东西。该变量包含将由所有 Controller 共享的变量。我正在为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>

child Dart 代码:
class MyChildComponent extends PolymerElement {
  @published var someAttribute;
}

换句话说,我一直将属性从最高父级一直传递到最低子级。我认为这样做不好,我想用类似于$ rootScope的方式进行操作。

最佳答案

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

关于angularjs - 在Polymer.dart中是否有类似于angular $ rootScope的东西?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31168865/

相关文章:

dart - 在 Dart 中创建扩展方法

flutter - 如何使变量成为最终变量并在 initState() 中为其赋值

javascript - polymer-webpack-loader : how to import & transpile Polymer . html模板

javascript - 如何通过指令在 AngularJS 中查找索引?

angularjs - 模型更改时不会调用 ngModel.$render

angularjs - 如何在 Jasmine 测试中注入(inject) Controller 依赖项?

css - 通过自定义属性动态更改元素样式?

javascript - AngularJS更新指令中显示的数据

audio - 如何在flutter中播放默认铃声?

javascript - 为什么 wecomponentsjs/custom-elements-es5-adapter.js 不工作