gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 03:18:21 25 4
gpt4 key购买 nike

我知道在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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com