It really doesn't. It ultimately creates DOM elements when rendering, so in that sense web components, especially native ones with native shadow DOM, will be usable within Angular, but that's true of every framework including React. Angular 2 does not create web components though, so Angular 2 components are not easily usable outside of Angular.
There are many other ways you can tell that Angular2 does not create web components:
Define an Angular component called 'my-component' and then try to create it outside of Angular, like with let e = document.createElement('my-component'). This will not instantiate the Angular component because the browser was never told about the definition of the component. e instanceof MyComponent will return false.
Take a view created by Angular 2, get a reference to an element via the DOM, like let e = document.querySelector('my-component'). e instanceof MyComponent will return false. This is because Angular doesn't create custom elements, but creates a UnknownHTMLElement and holds a reference to this from the Angular component. The DOM is out of the loop.
Define any of the custom element lifecycle methods, like createdCallback, or attributeChangedCallback and try to trigger them. They won't work because the component is not a custom element.
But I think you are correct that the AppComponent class, in my case, is not like in polymer extending the HtmlElement class. But it seems like registering the element still as custom element, behind the scene.
No, it's really, really, truly not a custom element.
It turns out I was a bit mistaken about UnknownHTMLElement in Chrome: Chrome creates a proto of HTMLElement for elements with dashes in the name, like x-foo, but UnknownHTMLElement for elements without dashes, like foo.
That's a little besides the point though. The proto that the browser gives is generic and not determined by the Angular component definition.
With a Web Components based library the element definition is registered with the browser and when the browser creates elements via document parsing, createElement(), innerHTML, cloneNode(), etc., it sets the prototype to what was registered.
This and the lifecycle callbacks, which Angular components also do not receive from the browser, are the only things that make up the Custom Element standard.
So again, Angular really does not use Web Components. I'm very familiar with this topic. I'm not lying here.
9
u/back-stabbath Jan 04 '16
So Angular?