lundi 16 février 2015

Making an Angular filter using $http?


I'd like to do an $http get request and return the result to the front-end. On the front-end, I use {{ URL-STRING | iframely }}.



'use strict'

angular.module( 'iframely', [] ).filter( 'iframely', [ '$http', function ( $http ) {
return function ( url ) {

var result = $http( {
url: 'http://localhost:8061/iframely',
method: 'GET',
params: {
url: url
}
})

return( result.then( function ( result ) {
console.log( result.data.html )
return result.data.html
}))
}
}])


The result is on the front-end I just get {} (looks like an empty object). But my console log shows the desired HTML.


I'm pretty sure the general set-up is right because if I just do return "it works" in there, that works. I think the problem is something about JS scoping, returns or $http that I'm not getting.





Aucun commentaire:

Enregistrer un commentaire