I bootstrapped my first Ember app today and created a service to call my login REST API and retrieve a user.
I’m using Promise
with my AJAX calls.
My code works properly when I hit my Ember app in the browser. The REST calls are made, and eventually the Promises resolve properly, or reject as expected if there was an error.
However, I noticed some noise in the ember serve
output.
Serving on http://localhost:4200/
services/session.js: line 15, col 16, 'Promise' is not defined.
services/session.js: line 33, col 16, 'Promise' is not defined.
services/session.js: line 50, col 16, 'Promise' is not defined.
3 errors
===== 1 JSHint Error
I’m assuming this is somehow related to JSHint. Though, the output says 3 errors
while below that it says 1 JSHint Error
. So that seems a bit confusing and I’m not sure if those are related or not.
If it is a JSHint related issue, I saw this article which made me think I had to add something to predef
in .jshintrc
.
This is what the predef
in my .jshintrc
file currently looks like. I haven’t modified it. This is the stock version.
{
"predef": [
"document",
"window",
"-Promise"
],
Perhaps I don’t fully understand how Ember uses promises. I thought that the native Promise syntax was alright.
Here’s a trivial example to illustrate what I’m doing in my app.
login(email, password) {
return new Promise((resolve, reject) => {
this.get('ajax').request('http://localhost/login', {
method: 'POST',
data: {
'Email': email,
'Password': password
}
}).then((data) => {
resolve(data);
}).catch(() => {
reject('Auth failed');
});
});
},
I’m assuming I’m missing something obvious. Any ideas on what that is?