javascript - Angular filter with $http response -


i need filter need make $http call , return response . trying use angular promise nothing works . return not waiting response . take below code. returning {} , not waiting $http response. need using filter only. idea keep separate controller , can used anywhere later.

.filter('filterxml',['testone','$sce',function(testone, $sce){      return function(url){         return testone.gettest(url).then(function(data){          return data;         });      }   }])   .factory('testone',  ['$http', function($http){    return {    gettest: function(url){     return $http.get(url).success(function(data){       console.log(data)       return data;     })   }  } }]) 

goal : {{ 'http://rss.cnn.com/rss/cnn_topstories.rss' | filterxml}}

so return data rss feed .

i don't want use controller . idea make separate module , call anywhere in application .

any appreciated . thanks

you shouldn't making http calls in filter that's not filters for. filters passed array of objects , objects pass condition returned in new filtered array.

i think want go set more this...

angular.module('foo', [])  .controller('somecontroller', ['$scope', '$filter', 'testone', function($scope, $filter, testone){      testone.gettest('foo/bar').then(function(data){       $scope.myfiltereddata = $filter('filterxml')(data);     });  }])    .filter('filterxml', function() {   return function(input) {     // condition on filter input goes here...     // dummy code have work out own logic     return (input === 'xml');   }; });   .factory('testone',  ['$http', function($http){    return {    gettest: function(url){     return $http.get(url)       .success(function(data){         console.log(data)         return data;       });   }  } }]) 

Comments

Popular posts from this blog

android - Gradle sync Error:Configuration with name 'default' not found -

java - Andrioid studio start fail: Fatal error initializing 'null' -

html - jQuery UI Sortable - Remove placeholder after item is dropped -