Issues calling service after submission w/ Angular 2
See original GitHub issueHi there,
I’m using Angular 2 w/ SweetAlert2.
swal({
title: 'Message All Models',
input: 'textarea',
inputPlaceholder: 'Type your message here',
showCancelButton: true
}).then(function() {
this.modelService.messageModels()
}, function(dismiss) {
console.log('Dismissed')
});
PROBLEM:
I’m able to run this service outside of the swal()
but for some reason when I run after the then()
I get the following error:
ERROR:
ERROR Error: Uncaught (in promise): TypeError: Cannot read property ‘modelService’ of undefined TypeError: Cannot read property ‘modelService’ of undefined at model-list.component.ts:174 - [ this is where service is called ]
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Angular 2 How do I call a service method when an observable ...
After get result from server, put it to array. Angular will update the data in the template itself, this is the fastest way....
Read more >Top 18 Most Common AngularJS Developer Mistakes - Toptal
Common Mistake #16: Not Running The Unit Tests In TDD Mode. Tests will not make your code free of AngularJS error messages. What...
Read more >Angular 4 form submit is not working #9019 - GitHub
I am using Angular 4 for my application development. When I submit my form it's calling the browser URL for posting.
Read more >Getting Past Hello World in Angular 2 - SitePoint
This post will give you a quick introduction to these concepts and how they apply to your Angular 2 applications.
Read more >Communicating with backend services using HTTP - Angular
Most front-end applications need to communicate with a server over the HTTP protocol, to download or upload data and access other back-end services....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
This is not a bug, this is a misuse of the language 😄
@m1xf1t: replace :
with :
That should work. The arrow function expression will bind the current context of
this
on the anonymous function being created (here, the component). Otherwise, usingfunction
, the scope ofthis
is volatile (not captured by the closure, contrarily to the other variables) and determined at the call site (inside SweetAlert).I suggest you to read one of the articles here: https://www.google.com/search?q=this+context+javascript (sorry for the Google link, no offense, I just don’t have a particular article in mind).
See Contributing.md