【发布时间】: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 的角度来做。
【问题讨论】:
-
您可以使用这里解释的全局变量stackoverflow.com/a/29864797/217408
标签: angularjs dart polymer dart-polymer angularjs-rootscope