Hi Guys,

I'm trying to fetch images from flickr's feed end point (see below). The 
response for some searches responds with an invalid json format containing 
a single quote. 

In Jquery we have access to converters (see code below) it basically 
manipulates the response before receiving (works great), is there a similar 
method available to angular 2 as yet?

PS: "https://crossorigin.me/"; is required to avoid CORS errors.

JQUERY METHOD:

    let urlCall = 
`https://crossorigin.me/https://api.flickr.com/services/feeds/photos_public.gne?tags=${query}&format=json&nojsoncallback=1`;

    $.ajax({
          type: 'GET',
          url: urlCall,
          dataType: 'json',
          async: true,
          converters: {
              "text json": function (textValue) {
                  return $.parseJSON(textValue.replace(/(^|[^\\])\\'/g, 
"$1'"));
              }
          },
          success: function(data) {
            var photo = [];

            return $.map(data.items,function (photo) {
              photo.url   = photo.media.m;
              photo.title = photo.title;
              photo.description = $(photo.description).text();
              photo.tags = photo.tags.split(" ");
            })
            
          }, error: function(data) {
            //error consoloe
            console.log('ERROR - AJAX CALL');
          }
          
        }); 


Angular method:

    return this._http.get(urlCall, { headers: headers })
             .map(res => res.json())
             .map((val) => {
                     return val.items.map((photo: any) => {
                         return {
                             url: photo.media.m,
                             title: photo.title
                         }
                     })
             })
            .catch((error:any) => Observable.throw(error.json().error || 
'Server error'));

-- 
You received this message because you are subscribed to the Google Groups 
"Angular" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to