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

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 >=/

1

u/schizoduckie Aug 28 '15

I have no idea what you mean. this should create a form with a regular formdata content-type. What kind of error are you seeing? because 'this doesn't work' is really not very useful

1

u/cj5 Aug 29 '15

I don't know, I've reverted my code before commit. I need to dive deeper into this when I have the time.

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.

2

u/[deleted] Aug 28 '15

You do realize that article is 3 years old right?

AngularJS 1.4.x allows urlencoding objects without dependencies or transformRequest

http://stackoverflow.com/a/30970229/2577889

We have a problem in this subreddit of people not even caring to look for a solution before posting a thread about it.

1

u/cj5 Aug 28 '15

Yes, but I am using version 1.4.4, and this fix is relevant. If there is a newer fix, please, let me know.

2

u/ergo14 Aug 29 '15

IF you wanted jquery i think you should just stick to jquery, it seems unreasonable to assume that frameworks are supposed to behave same way. Whats the point of creating them in first place.

0

u/cj5 Aug 29 '15

First of all, jQuery's approach to what AngularJS does is convoluted and basically sucks. AngularJS I assumed did it better, up until I hit this wall.

2

u/ergo14 Aug 29 '15

I have no idea what you are talking about but it kind of sounds like you are hitting this:

http://www.bennadel.com/resources/uploads/2013/feelings_about_angularjs_over_time.png

1

u/liflo Aug 28 '15

Out of curiosity, what backend are you hitting with these requests?

0

u/[deleted] Aug 28 '15

[deleted]

1

u/cj5 Aug 28 '15

I have to do this for each module?

0

u/[deleted] Aug 28 '15

[deleted]

1

u/cj5 Aug 28 '15

Okay. I have multiple apps per page (I am compartmentalizing function). Is there a place globally I can set this?

0

u/[deleted] Aug 28 '15

[deleted]

1

u/cj5 Aug 28 '15

I see. Thank you. Ignorance on my part. Will study that guide.