Using jquery in angular when returning data from a $ http.get request
I am making a request $http.get
to the apache server and the response is an HTML page. I would like to use jquery for some data from an HTML page.
My controller code:
app.controller('MainController', ['$scope', '$http', function($scope, $http) {
$scope.showImages = function() {
$http.get('http://localhost/images/').success(function(data) {
$scope.images = data;
});
};
}]);
I can see that the $scope.images
html page is being stored returning from the server, but I have no clue on how to use jquery to retrieve, for example, the value of all the hrefs that appeared on the page.
+3
source to share
3 answers
If you want to extract any information, you can get the data directly. Just add a data type to call and use jQuery (data) to access the html
app.controller('MainController', ['$scope', '$http', function($scope, $http) {
$scope.showImages = function() {
$http.get('http://localhost/images/',
dataType: "html").success(function(data) {
// Now use this html Object as normal object and retrieve information
var htmlObject = jQuery(data);
$scope.images = data;
});
};
}]);
+2
source to share