Discussion:
[dart-misc] Adding event listener to dynamicly loaded content
Mateusz Lewandowski
2016-09-25 20:46:22 UTC
Permalink
Hi.
i have a problem with add on click event listener on dynamicly loaded html
( on button click)
When i am trying to listen on click event the error occurs.
"Uncaught Unhandled exception:
The null object does not have a getter 'onClick'."

I have the following

Logon logon=new Logon();


DivElement div = querySelector('#MainContent');

EventListener HandleEvent(event)// async
{

switch(event.detail) {
case 'Logowanie':
{
HttpRequest.getString("logon.html").then((resp) {
div.append(new Element.html(resp));
});
div.querySelector("#login").onClick.listen((e) {
print("Loading...");
logon.LoginMethod();
});

break;
}
}
}

main() async{


document.addEventListener('todochange',HandleEvent);

...

}


I have tried different ways with no result.
Please help me with this.
--
For other discussions, see https://groups.google.com/a/dartlang.org/

For HOWTO questions, visit http://stackoverflow.com/tags/dart

To file a bug report or feature request, go to http://www.dartbug.com/new
---
You received this message because you are subscribed to the Google Groups "Dart Misc" group.
To unsubscribe from this group and stop receiving emails from it, send an email to misc+***@dartlang.org.
Jan Mostert
2016-09-26 06:28:41 UTC
Permalink
You need to add the click listener in the callback after your HTML is
loaded.
Otherwise the HTML has not been loaded into the div yet.
Post by Mateusz Lewandowski
Hi.
i have a problem with add on click event listener on dynamicly loaded html
( on button click)
When i am trying to listen on click event the error occurs.
The null object does not have a getter 'onClick'."
I have the following
Logon logon=new Logon();
DivElement div = querySelector('#MainContent');
EventListener HandleEvent(event)// async
{
switch(event.detail) {
{
HttpRequest.getString("logon.html").then((resp) {
div.append(new Element.html(resp));
});
div.querySelector("#login").onClick.listen((e) {
print("Loading...");
logon.LoginMethod();
});
break;
}
}
}
main() async{
document.addEventListener('todochange',HandleEvent);
...
}
I have tried different ways with no result.
Please help me with this.
--
For other discussions, see https://groups.google.com/a/dartlang.org/
For HOWTO questions, visit http://stackoverflow.com/tags/dart
To file a bug report or feature request, go to http://www.dartbug.com/new
---
You received this message because you are subscribed to the Google Groups
"Dart Misc" group.
To unsubscribe from this group and stop receiving emails from it, send an
--
For other discussions, see https://groups.google.com/a/dartlang.org/

For HOWTO questions, visit http://stackoverflow.com/tags/dart

To file a bug report or feature request, go to http://www.dartbug.com/new
---
You received this message because you are subscribed to the Google Groups "Dart Misc" group.
To unsubscribe from this group and stop receiving emails from it, send an email to misc+***@dartlang.org.
Jan Mostert
2016-09-26 06:30:33 UTC
Permalink
I believe this should fix it ?
HttpRequest.getString("logon.html").then((resp) {
div.append(new Element.html(resp));

div.querySelector("#login").onClick.listen((e) {
print("Loading...");
logon.LoginMethod();
});

});
Post by Jan Mostert
You need to add the click listener in the callback after your HTML is
loaded.
Otherwise the HTML has not been loaded into the div yet.
On Sun, 25 Sep 2016 at 22:46 Mateusz Lewandowski <
Post by Mateusz Lewandowski
Hi.
i have a problem with add on click event listener on dynamicly loaded
html ( on button click)
When i am trying to listen on click event the error occurs.
The null object does not have a getter 'onClick'."
I have the following
Logon logon=new Logon();
DivElement div = querySelector('#MainContent');
EventListener HandleEvent(event)// async
{
switch(event.detail) {
{
HttpRequest.getString("logon.html").then((resp) {
div.append(new Element.html(resp));
});
div.querySelector("#login").onClick.listen((e) {
print("Loading...");
logon.LoginMethod();
});
break;
}
}
}
main() async{
document.addEventListener('todochange',HandleEvent);
...
}
I have tried different ways with no result.
Please help me with this.
--
For other discussions, see https://groups.google.com/a/dartlang.org/
For HOWTO questions, visit http://stackoverflow.com/tags/dart
To file a bug report or feature request, go to http://www.dartbug.com/new
---
You received this message because you are subscribed to the Google Groups
"Dart Misc" group.
To unsubscribe from this group and stop receiving emails from it, send an
--
For other discussions, see https://groups.google.com/a/dartlang.org/

For HOWTO questions, visit http://stackoverflow.com/tags/dart

To file a bug report or feature request, go to http://www.dartbug.com/new
---
You received this message because you are subscribed to the Google Groups "Dart Misc" group.
To unsubscribe from this group and stop receiving emails from it, send an email to misc+***@dartlang.org.
Mateusz Lewandowski
2016-09-26 18:53:29 UTC
Permalink
It works.
Thanks a lot
Post by Jan Mostert
I believe this should fix it ?
HttpRequest.getString("logon.html").then((resp) {
div.append(new Element.html(resp));
div.querySelector("#login").onClick.listen((e) {
print("Loading...");
logon.LoginMethod();
});
});
Post by Jan Mostert
You need to add the click listener in the callback after your HTML is
loaded.
Otherwise the HTML has not been loaded into the div yet.
On Sun, 25 Sep 2016 at 22:46 Mateusz Lewandowski <
Post by Mateusz Lewandowski
Hi.
i have a problem with add on click event listener on dynamicly loaded
html ( on button click)
When i am trying to listen on click event the error occurs.
The null object does not have a getter 'onClick'."
I have the following
Logon logon=new Logon();
DivElement div = querySelector('#MainContent');
EventListener HandleEvent(event)// async
{
switch(event.detail) {
{
HttpRequest.getString("logon.html").then((resp) {
div.append(new Element.html(resp));
});
div.querySelector("#login").onClick.listen((e) {
print("Loading...");
logon.LoginMethod();
});
break;
}
}
}
main() async{
document.addEventListener('todochange',HandleEvent);
...
}
I have tried different ways with no result.
Please help me with this.
--
For other discussions, see https://groups.google.com/a/dartlang.org/
For HOWTO questions, visit http://stackoverflow.com/tags/dart
To file a bug report or feature request, go to
http://www.dartbug.com/new
---
You received this message because you are subscribed to the Google
Groups "Dart Misc" group.
To unsubscribe from this group and stop receiving emails from it, send
--
For other discussions, see https://groups.google.com/a/dartlang.org/
For HOWTO questions, visit http://stackoverflow.com/tags/dart
To file a bug report or feature request, go to http://www.dartbug.com/new
---
You received this message because you are subscribed to the Google Groups
"Dart Misc" group.
To unsubscribe from this group and stop receiving emails from it, send an
--
For other discussions, see https://groups.google.com/a/dartlang.org/

For HOWTO questions, visit http://stackoverflow.com/tags/dart

To file a bug report or feature request, go to http://www.dartbug.com/new
---
You received this message because you are subscribed to the Google Groups "Dart Misc" group.
To unsubscribe from this group and stop receiving emails from it, send an email to misc+***@dartlang.org.
Loading...