Home >Web Front-end >JS Tutorial >Points to note when using $.ajax in angularJs
This article mainly introduces the points to note about using $.ajax in angularJs. The editor thinks it is quite good, so I will share it with you now and give it as a reference. Let’s follow the editor and take a look.
This article introduces the points to note about using $.ajax in angularJs and shares it with everyone. The details are as follows
Technically speaking, angular and It is not appropriate to mix jquery, but why this topic is still debated is a matter of opinion.
In addition to convenience, it is also possible that jquery is indeed more comprehensive than angular in some aspects. For example, ajax cross-domain aspect.
When I usually develop with angular, I basically just use angular. Even if there is angular.element, I try to use it as little as possible. I suggest that if you use a framework, try to use only one, because these are all It is an encapsulation method, and there will inevitably be conflicts. It will be more difficult if there is a bug.
Go straight to the topic:
When ajax cross-domain or parameter type (dataType) needs to be set, $http will appear very awkward, then at this time I thought of using $.ajax;
Originally $.ajax is no better to write than $http ink, but after writing it I found a problem. The view layer has no regard for the objects processed by $.ajax. Pay attention.
The feature of angular is two-way binding. To be more complicated, there is a dirty value detection system, which mainly includes: $watch and $digest;
There is a thing in triggering $digest Called $apply, $apply is considered the most standard way to mix AngularJs with third-party libraries.
$.ajax({ data:{}, url:'', type/method:'', dataType:'', success: function(){ $scope.$appy(); } } )
After the processing is completed, just add $scope.$apply(). This method is also suitable for setTimeout, setInterval, etc...
But I still recommend not to use third-party libraries when you can't.
The above is the detailed content of Points to note when using $.ajax in angularJs. For more information, please follow other related articles on the PHP Chinese website!