angular.js icon indicating copy to clipboard operation
angular.js copied to clipboard

Polymer webcomponents never fires click event

Open vrunoa opened this issue 12 years ago • 7 comments

I add a polymer webcomponent to my angular app and the click event of the custom element never fires.

How should I rewrite the code so the webcomponent can work on an agular.js app ?

Here's the webcomponent and the source: http://urucas.github.io/button-spring/ https://github.com/Urucas/button-spring

vrunoa avatar Sep 24 '14 01:09 vrunoa

Hi, this isn't an actionable issue:

  1. the issue is in the form of a question with zero context provided
  2. there is no reproduction of the issue about which the question is asked
  3. there's no information about how your code is interacting with the component, at all
  4. there is no information about what version of polymer-platform you're using at all
  5. there is no information about what version of angular you're using here

So, the component you linked is not preventing the event from bubbling. click events do bubble, and are not prevented from crossing the shadow root boundary in Chrome/Blink (I haven't checked webkit nightly, but it looks like Safari 7.0.2/FF Nightly don't ship unprefixed (or prefixed, as far as I can tell) shadow DOM). (http://jsbin.com/nemipejemuki/1/edit for example).

Anyways, since the events should cross the shadow boundary, there should be no reason why ng-click would not get the event.

WITH THE FOLLOWING EXCEPTION: the compiler will not descend down into the shadowRoot of any element, because it just doesn't. So in order to compile elements within a shadow tree, you need to manually invoke $compile, otherwise ng-click attributes within the shadow tree will be completely missed by angular.

@tbosch do you think it would be a good project to get the angular compiler to descend into shadowRoot in 1.x? It probably isn't going to happen, but we do have some support for the shadow DOM in terms of searching up into shadow hosts in jqLite#inheritedData() to find required controllers across shadow boundaries.

caitp avatar Sep 24 '14 02:09 caitp

tentatively calling this wontfix because I sort of predict that's how it will end up, but I would love to try and make the compiler deal with shadow trees at some point

caitp avatar Sep 24 '14 02:09 caitp

@caitp sorry for the missing information. Tomorrow i'll create a post with all the items missing. Thanks for your reply.

vrunoa avatar Sep 24 '14 03:09 vrunoa

I was wondering about angular compiling shadow DOM and happened to come across this -- is Angular's handling of Shadow DOM documented anywhere?

maxbates avatar Sep 26 '14 18:09 maxbates

angular predates the shadowDOM and was never designed to deal with it, the compiler still does not descent into an element's shadow root.

Angular.dart does this, but it's a much newer project. Angular 2.0 will most likely be doing this, but it's a much newer project. 1.x is probably not going to be able to do this, and if it does, it will probably end up being really bad.

The easiest solution is to just manually compile the contents of your shadow DOMs when you need to

caitp avatar Sep 26 '14 18:09 caitp

I was hoping to use it as more of a feature -- If I create a directive which is a web-component wrapper, and bootstrap another app in it's shadow dom (so one app in another), should that in theory be ok?

Edit - example at http://www.mbates.com/play/angularInShadowDOM/

maxbates avatar Sep 26 '14 18:09 maxbates

I created a simple angular app and add my polymer element via ng-include and it works. Before I was trying to include It on an Ionic app. I guess it must a problem with ionic including polymer elements.

So, my polymer element worked with angular. https://github.com/Urucas/button-spring/blob/angular-problem/index.html https://github.com/Urucas/button-spring/blob/angular-problem/app.js https://github.com/Urucas/button-spring/blob/angular-problem/main.html

Sorry. I'll close this issue.

vrunoa avatar Oct 06 '14 03:10 vrunoa