在Polymer Getting Started页面上,我们看到Polymer的实例:
<html>
<head>
<!-- 1. Shim missing platform features -->
<script src="polymer-all/platform/platform.js"></script>
<!-- 2. Load a component -->
<link rel="import" href="x-foo.html">
</head>
<body>
<!-- 3. Declare the component by its tag. -->
<x-foo></x-foo>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
您将注意到的是<x-foo></x-foo>由platform.js和定义的x-foo.html.
看起来这相当于AngularJS中的指令模块:
angular.module('xfoo', [])
.controller('X-Foo', ['$scope',function($scope) {
$scope.text = 'hey hey!';
})
.directive('x-foo', function() {
return {
restrict: 'EA',
replace: true,
controller: 'X-Foo',
templateUrl: '/views/x-foo.html',
link: function(scope, controller) {
}
};
});
Run Code Online (Sandbox Code Playgroud)
两者有什么区别?
Polymer解决AngularJS没有或不会有什么问题?
是否有计划在未来将Polymer与AngularJS联系起来?