如何访问组件外部的AngularDart组件属性(NgOneWay),例如。在它的页面上? [英] How to access a AngularDart components attribute (NgOneWay) outside of the component, eg. on the page it is in?

查看:320
本文介绍了如何访问组件外部的AngularDart组件属性(NgOneWay),例如。在它的页面上?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个页面中的AngularDart组件。

Here is a AngularDart component in a page.

<body>
<testcomponent></testcomponent>
  <p>Should have value {{testcomponent.test}}</p>
</body>

组件的NgOneWay为

The component has a NgOneWay of

@NgOneWay("test")
String test = "HELLO";

这不工作,因为没有值显示在页面上。组件可以在组件HTML中显示其NgOneWay,但是我希望在组件使用的页面的组件HTML之外访问它。

This does not work as no value is shown on the page. The component can show its NgOneWay within the components HTML but I wish to access it outside of the components HTML on the page where the component is used.

有任何方法在组件使用的页面上显示组件NgOneWay?

Is there any way to show the components NgOneWay on the page in which the component is being used?

这里是我的测试代码。
http://www.topazbooking.com/test2.zip

Here is my test code. http://www.topazbooking.com/test2.zip

我使用Dart 1.5.1

I am using Dart 1.5.1

好的做法,它创建使用组件的页面和组件本身之间的依赖性。我有的问题是,我使用一些javascript在组件内不工作,这是一个不同的问题...我不应该解释这里,但我试图使用视图,而不是组件,因为我的js工作在

Ok I understand its not a good practice, it creates a dependancy between the page using the component and the component itself. The problem I have is that I use some javascript which doesn't work within the component, that's a different problem ... I shouldn't explain here but I was trying to use the view only and not component as my js worked in the view but not in the component.

推荐答案

简而言之:无法在组件外部获取属性,因为组件不要这样做

In short : No you can't get the attribute outside the component, because component is not make to do this

在Angular Dart中,组件需要被视为一个黑盒子,你可以像lego一样创建一个结构化应用程序。
您不能在其他地方使用lego的一部分。

In Angular Dart, Component need to be see as a black box that you can compose like lego to create a structured application. You can't use a part of a piece of lego somewhere else.

您的信息 NgOneWay NgAttr NgTwoWay 这里与您的组件交互,但作为HTML属性。

For you information NgOneWay, NgAttr and NgTwoWay are here to interact with your component but as HTML attribute.

一个例子:

<body>
<testcomponent test="Hi friend"></testcomponent>
</body>

但您可以在组件中获取您的属性

But you can get your attribute inside the component

testcomponent.html

<div>
     <p>Should have value {{testcomponent.test}}</p>
</div>

如果你真的想得到你想要的行为,你需要使用控制器

If you really want to get the behavior that you want, you need to use Controller

注意:您可以欺骗,如果你想通过添加静态值。但不是最好的方法。

这篇关于如何访问组件外部的AngularDart组件属性(NgOneWay),例如。在它的页面上?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆