aurelia / templating

An extensible HTML templating engine supporting databinding, custom elements, attached behaviors and more.
MIT License
116 stars 103 forks source link

Uncaught TypeError: elem.getAttribute is not a function #156

Closed michaelmalonenz closed 8 years ago

michaelmalonenz commented 9 years ago

The problem is that the error in the title shows up on the console when I click any Delete Month buttons.

I have a sample application here which shows the problem.

But it essentially boils down to the use of trigger vs delegate in this particular scenario, because if I change (in src/bookingmonthview.html):
<button class="btn btn-link btn-sm" click.trigger="delete()">Delete Month</button>
to
<button class="btn btn-link btn-sm" click.delegate="delete()">Delete Month</button>
The problem goes away. I have made the change in my code, but it might be useful for someone else in the future. Especially when searching the interwebs shows up the opposite advice, as seen here: https://github.com/aurelia/templating/issues/20

alexmills commented 9 years ago

@michaelmalonenz you're the man, I was having the same issue and this solved it! Thanks!

jdanyow commented 9 years ago

duplicate of https://github.com/aurelia/templating/issues/20

EisenbergEffect commented 8 years ago

Should be fixed a while ago now.

stsje commented 8 years ago

Should this be fixed in 1.0.0-beta.1 version? We're still experiencing the error.

The error occurs when the click handler is navigating to another route. Switching to delegate instead of trigger fixes the error.

html:

<i class="fa fa-sign-out" click.trigger="onSignOutClick()"  title="Log af"></i>

js:

    onSignOutClick(){
        this.eventAggregator.publish(new LoggedOutEvent());
        this.router.navigateToRoute('login');
    }
valichek commented 8 years ago

Hey, guys, I have created a plunker for that error, in 1.0.0-beta.1 Now it's not about trigger/delegate but about repeat.for and replacing binded array. Also it is related to jquery, is gone if import 'bootstrap' removed http://plnkr.co/edit/yNR9h9

Uncaught TypeError: elem.getAttribute is not a function
Sizzle.attr @ jquery.js:1451
(anonymous function) @ jquery.js:1647
(anonymous function) @ jquery.js:2148
superMatcher @ jquery.js:2366
Sizzle.select @ jquery.js:2536
Sizzle @ jquery.js:855
jQuery.event.handlers @ jquery.js:4480
jQuery.event.dispatch @ jquery.js:4417
elemData.handle @ jquery.js:4121
timfish commented 8 years ago

Should this be reopened or a new issue created? I'm seeing this error too in 1.0.0-beta.1

jdanyow commented 8 years ago

This isn't really an Aurelia bug, what's happening is both Bootstrap and your code are handling events and doing things that result in DOM changes. A race condition essentially. If you use trigger you'll beat Bootstrap to the punch (it uses event delegation) and if you use delegate Bootstrap will win the race because it's event delegation subscription was setup prior to Aurelia's (Aurelia's is set up lazily).

When you run into this issue, use delegate or prevent the event from bubbling if you want to continue using trigger.

timfish commented 8 years ago

Many thanks for looking into this