r/angularjs • • Aug 28 '15

Why, AngularJS?

http://victorblog.com/2012/12/20/make-angularjs-http-service-behave-like-jquery-ajax/

This is a huge deal breaker for me. Are the devs addressing this or is it something they don't plan on supporting?

0 Upvotes

15 comments sorted by

View all comments

2

u/schizoduckie Aug 28 '15 edited Aug 28 '15

This article is severely outdated and the wrong way to post forms like this. You want to use angular.identity (which is basically a 'passthrough' transformer) for this and a FormData object:

var fd = new FormData();
fd.append('addlinktext', magnet);
fd.append('addlink', 'Add');

return $http.post(this.getUrl('addmagnet'), fd, {
    transformRequest: angular.identity,
    headers: {
        'Content-Type': undefined
    }
});

You can even upload files like this with zero effort, example here

-2

u/cj5 Aug 28 '15 edited Aug 28 '15

Sorry, but this doesn't work. I didn't think this would be put on the framework coder to handle transforms, and really breaks the flow of things. Wish I knew this before diving into angularjs >=/

2

u/schizoduckie Aug 28 '15 edited Aug 28 '15

Also, please stop blaming the framework for not working like you're expecting with $random other framework. They all work different. Angular may not be the most newbie friendly, but it's an opinionated and well thought-out framework and everything is possible. It took me a full year to get fully up to speed, and that requires faling, failing failing and then finally finding the right way. "$x should work like in jquery" is exactly the train of thought that you need to let go.