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

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

问题描述

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

<testcomponent></testcomponent><p>应该有值{{testcomponent.test}}</p>

该组件有一个 NgOneWay

@NgOneWay("test")字符串测试 = "你好";

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

有没有什么办法可以在使用组件的页面上显示组件NgOneWay?

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

我使用的是 Dart 1.5.1

<小时>

好的,我知道这不是一个好的做法,它在使用组件的页面和组件本身之间创建了依赖关系.我遇到的问题是我使用了一些在组件中不起作用的 javascript,这是一个不同的问题......我不应该在这里解释但我试图只使用视图而不是组件,因为我的 js 在查看但不在组件中.

解决方案

简而言之:不,你不能在组件外获取属性,因为组件不是这样做的

在 Angular Dart 中,组件需要被视为一个黑盒子,您可以像乐高积木一样组合它来创建结构化应用程序.你不能在别处使用乐高积木的一部分.

为您提供信息 NgOneWayNgAttrNgTwoWay 在这里与您的组件交互,但作为 HTML 属性.

一个小例子:

<testcomponent test="嗨朋友"></testcomponent>

但是你可以在组件内部获取你的属性

testcomponent.html

<p>应该有值{{testcomponent.test}}</p>

如果你真的想得到你想要的行为,你需要使用 Controller

注意:如果需要,您可以通过添加静态值来欺骗.但不是这样做的好方法

Here is a AngularDart component in a page.

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

The component has a NgOneWay of

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

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.

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

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

I am using Dart 1.5.1


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

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.

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

A little example:

<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

Note: You can trick if you want by adding static value. but is not the good way to do it

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

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