Home > Web Front-end > JS Tutorial > body text

Points to note when using $.ajax in angularJs

黄舟
Release: 2017-08-13 10:51:31
Original
1256 people have browsed it

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();
    }
  }
)
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!