Polymer通过Node.bind()管理数据绑定. Node.bind() is a “new method added to all DOM nodes which instructs them to bind the named property to the data provided”. Angular does not use Node.bind() out of the box, so Angular is unable to listen for changes that are initiated from Polymer.
Justin Fagnani, an engineer on the Dart team, released angular_node_bind, a Dart package that bridges the Angular and Polymer worlds. It is an Angular module that can listen for Node.bind() changes and propagate the changes into Angular.
Justin explains why this package can help:
Node.bind() takes care of setting up the binding, including two-way bindings, eliminating the need for directives for every property for two-way bindings.
Custom elements that expose properties will be properly bound, again including two-way bindings. You can use the growing collection of custom element libraries in your Angular app.
To use angular_node_bind, add the following to your app’s pubspec.yaml file:
1
name: angularpolymer
description: A demo of Angular and Polymer data binding.
dependencies:
angular: any
angular_node_bind: any
browser: any
polymer: any
transformers:
- polymer:
entry_points: web/angularpolymer.html
注册NodeBindModule
1
import 'package:polymer/polymer.dart' show initPolymer;
import 'package:angular/angular.dart' show ngBootstrap;
import 'package:angular_node_bind/angular_node_bind.dart' show NodeBindModule;
void main() {
initPolymer().run(() {
ngBootstrap(module: new NodeBindModule());
});
}