I don't understand when to use Angular over jquery for ajax requests.
For example, why should I use:
function ItemListCtrl ($scope, $http) {
$http.get('example.com/items').success(function (data) {
$scope.items = data;
}
}
Instead of
function ItemListCtrl ($scope) {
$.ajax({type: "GET", url: 'example.com/items',
success: function (result) {
$scope.items = data;
}
});
}
??
My understanding is that there are a couple reasons the first is preferred:
Aside from those, though, you generally should be able to do either.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With