当前位置: 动力学知识库 > 问答 > 编程问答 >

javascript - AngularJS custom directives and webcomponents are Same?

问题描述:

I have working on angularJS for quite some time and able to understand to an extent, Now I like to know the emerging webcomponents (http://webcomponents.org/ ) lets say polymer (https://www.polymer-project.org/0.5/), X-tags (http://www.x-tags.org/) or many others are similar to that of AngularJS directive behavior.

Ex:

myapp = angular.module("myapp", []);

myapp.directive('element', function() {

var directive = {};

directive.restrict = 'E'; /* restrict this directive to elements */

directive.template = "My first directive: {{textToInsert}}";

return directive;

});

In HTML

<element></element>

Now the Polymer example

HTML:

<element></paper-tabs>

JS:

<script>

var tabs = document.querySelector('element');

tabs.addEventListener('core-select', function() {

console.log("Selected: " + tabs.selected);

});

</script>

My Question is: If my understanding is correct (Angular Directives are similar to polymers), If so, There is no point to use webcomponents in my app, when I chose AngularJS as my core framework to create apps.

网友答案:

Angular Directives and Web-Components are NOT the same.

All Angular Directives are compiled to regular HTML when a page loads up in the browsers by Angular.

Where as Web Components are actual custom-elements that make use of ShadowDOM and few other Specifications which Angular knows nothing about.

Polymer is a library that Sugar-coats Web-Components API.

Both of these Technologies Full Fill very much the same needs and it is up to choice to use one of these Frameworks.

分享给朋友:
您可能感兴趣的文章:
随机阅读: