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


If you understand correctly, you need to parse the HTML before doing any manipulation. See this SO post.



+2


source


If you want to display an image, you only need the path / url of the image from the server, not the image data or HTML.

+2


source







All Articles