【问题标题】:How to reference AngularDart component attributes outside of component scope如何在组件范围之外引用 AngularDart 组件属性
【发布时间】:2015-03-03 12:30:37
【问题描述】:

我的任务是使用 AngularDart 创建一个 web 应用程序。我是 Dart 的新手,因此也是 AngularDart 的新手,但我已经完成了 https://angulardart.org/tutorial/ 的教程。

我已经阅读过类似的 SO 问题/答案 (How to access a AngularDart components attribute (NgOneWay) outside of the component, eg. on the page it is in?),但鉴于我的知识有限,我并不完全理解如何实施 Brian 的建议——或者如果它确实与我的问题有关!我是否也认为 Vink 的建议现在与 @Controller 已被弃用无关?

简而言之,我试图弄清楚以下是否真的可以实现:

  • 创建一个包含属性的顶级<custom-component/>
  • <ng-view/> 内——因此是嵌套组件——访问<custom-component/> 的属性。更具体地说,绑定/侦听对这些属性的更改并采取相应措施。

例如,给定以下

<body>
    <custom-component att1="val1" att2="val2"></custom-component>
    <ng-view></ng-view>
</body>

并假设&lt;ng-view/&gt; 呈现以下标记

<div>
    ...
    <other-component att1="{{customComponent.att1}}" att2="{{customComponent.att2}}"></other-component>
    <another-component att1="{{customComponent.att1}}" att2="{{customComponent.att2}}"></another-component>
    ...
</div>

是否可以将customComponent.&lt;&lt;attributeName&gt;&gt; 绑定到&lt;other-component/&gt;&lt;another-component/&gt;

或者,很可能,我误解了 AngularDart 的 @Component/@Decorator 的使用?

是否应该将@att1@att2 属性从&lt;custom-component/&gt; 移动到&lt;ng-view/&gt;

或者,我应该寻求完全不同的解决方案吗?在这种情况下,我的最终目标是为用户提供att1/att2 选择框(来自另一个组件),这反过来又确定了&lt;other-component/&gt;&lt;another-component/&gt; 中的每个渲染内容。

欢迎任何和所有建议,如果您忽略以上任何/所有建议,我不会被冒犯!!!

我目前的开发环境如下:

  • Dart SDK 版本 1.9.0-dev.8.0
  • 角度 1.0.0

非常感谢,J

【问题讨论】:

    标签: dart angular-dart


    【解决方案1】:

    您可以做的是将这两个组件移动到包装器组件的内容(模板)中,并将两个组件的属性绑定到包装器元素的字段。

    通常更好的方法是使用 How to communicate between Angular DART controllersAngular Dart component events 中所示的事件(从那时起,控制器已与组件合并)

    【讨论】:

    • 感谢您的建议。我读过那些文章,但一定不明白。我再看看……
    • 如果您有具体问题,请添加评论。
    猜你喜欢
    • 2015-08-13
    • 1970-01-01
    • 2012-11-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-02
    • 2014-09-25
    • 2017-03-01
    相关资源
    最近更新 更多