-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Fix minor errors in code samples #41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
The first you are correct. Nice catch. The second does work as shown, its direct from my code. If you want to revise the PR, I'll merge |
Are you using it it with |
Yep, correct. Thanks for the second set of eyes. I had switched form success to then and didn't update the code. function getAvengers() {
return $http.get('/api/maa')
.then(getAvengersComplete)
.catch(function(message) {
exception.catcher('XHR Failed for getAvengers')(message);
$location.url('/');
});
function getAvengersComplete(response) {
return response.data[0].data.results;
}
} |
Fix minor errors in code samples
Awesome. Thanks for putting this guide together. :) Not sure how picky we should be with the examples but This example also reminds me of a very common anti-pattern that might be worth mentioning in the style guide, which is to return the promise from
The calls to the service end up either dealing with the
Or they use the
Both leak the underlying |
Good questions. Regarding the First, I prefer showing the then and the catch separately, for clarity. So that part is a preference. Second, the In short, using Regarding the $http examples you mention ... I agree that returning the I'll think about how to articulate that in the guide, if I decide to add it. -- Thanks to @wardbell for his input on this, as he is the one who pointed it out to me. |
Excellent point on why |
John and I were just talking about this a minute ago. We like We could really be splitting hairs here. p.s.: there is no harm in having an extra promise in the chain. |
good question and chat ... next time put it in its own issue so folks can discover it :) |
Just a couple of minor fixes...
vm.refresh = dataservice.refresh();
should probably bevm.refresh = dataservice.refresh;
$http
'sthen()
passes its success and error callbacks a response object. The data is in the response object'sdata
property.