在Dart中Angular和Polymer之间的对象绑定 [英] Object binding between Angular and Polymer in Dart

查看:194
本文介绍了在Dart中Angular和Polymer之间的对象绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图绑定一个对象从角控制元素到Dart中的Polymer元素。

I'm trying to bind an object from an Angular controlled element to a Polymer element in Dart.

要绑定的对象:

class Person {
  String name;
  String surname;

  Person(this.name, this.surname);
}

聚合物元素模板:

<link rel="import" href="packages/polymer/polymer.html">

<polymer-element name="person-element">
  <template>
    <style>
     .label {font-weight: bold;}
    </style>
    <p>
      <span class="label">Name: </span>{{person.name}}
      <span class="label">Surname: </span>{{person.surname}}
    </p>
  </template>
  <script type="application/dart" src="person_element.dart"></script>
</polymer-element>

聚合物元素代码:

import 'package:polymer/polymer.dart';
import 'person.dart';

@CustomTag('person-element')
class PersonElement extends PolymerElement {
  @published Person person;

  PersonElement.created() : super.created();
}



在Angular中我创建了一个控制器和一个模块:

In Angular I've created a controller and a module:

@Controller(
    selector: '[person-container]',
    publishAs: 'ctrl')
class PersonController { 
  List<Person> persons = [new Person('John','Smith'), new Person('Mario','Rossi')];
}

class PersonModule extends Module {
  PersonModule() {
    bind(PersonController);
  }
}

第一个解决方案正在使用 angular_node_bind 包:

<div person-container ng-cloak>
  <h2>Person elements</h2>
  <div ng-repeat="person in ctrl.persons">
    <div>{{person.name}}</div>
    <person-element person="[[person]]"></person-element>
  </div>
</div> 

当我在Dartium中运行应用程序时出现错误:

When I run the application in Dartium I get this error:

Exception: type 'String' is not a subtype of type 'Person' of 'value'. (http://localhost:8080/person_element.dart:6)

以这种方式修改html代码中的属性实例化:

I've also tried to modify the attribute instantiation in the html code in this way:

<person-element person=[[person]]></person-element>

但是我也有同样的异常。

But I get the same exception.

angular_node_bind包支持对象绑定?

The angular_node_bind package supports the object binding?

第二个解决方案使用 Angular 0.14.0的新绑定特征,并以这种方式绑定聚合物元素:

The second solution is using the new binding features of Angular 0.14.0 and binding the polymer element in this way:

使用这个解决方案我没有得到任何异常,元素是可视化的,但字段是空的, 。

With this solution I don't get any exception, the element is visualized but the fields are empty and the person instance null.

完整的示例如下: https://github.com/fedy2/dart-angular-polymer-object-data-binding

推荐答案

新版本的AngularDart(0.14.0)支持Polymer-Dart绑定( http:// blog .angulardart.org )。
目前,不同版本可能会有一些问题:
发布获取失败,[1]解析依赖项...对code_transformers的版本限制不兼容

The new version of AngularDart (0.14.0) has a support for Polymer-Dart binding (http://blog.angulardart.org). At the moment there can be some problems with different versions: Pub get failed, [1] Resolving dependencies... Incompatible version constraints on code_transformers

这篇关于在Dart中Angular和Polymer之间的对象绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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