相关疑难解决方法(0)

Polymer元素和AngularJS指令有什么区别?

在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联系起来?

javascript angularjs polymer

520
推荐指数
6
解决办法
9万
查看次数

标签 统计

angularjs ×1

javascript ×1

polymer ×1