Exploring the Polymer Getting Started guide reveals a practical example showcasing Polymer's capabilities:
<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>
The definition of <x-foo></x-foo>
relies on files like platform.js
and x-foo.html
.
This structure bears resemblance to AngularJS's directive module concept, as evidenced below:
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) {
}
};
});
What distinguishes these two approaches?
Which challenges does Polymer tackle that AngularJS may not address?
Is there potential for combining Polymer with AngularJS down the line?