ajax call using service

by Keval Bhatt

HTML

<div ng-app='demoService' ng-controller='myctr'>{{ test}}</div>

JavaScript

var demoService = angular.module('demoService', [])
.controller('myctr',['$scope','myService',function($scope,myService){
   myService.getdata('yahoo').then(function(response){
            //Success
       console.log(response)

        },function(response){

            //Error         
        });

}]);


demoService.service('myService',['$http', function($http) {

    this.getdata = function(entity){
        
        var promise = $http({
            method : 'GET',
            url : 'http://d.yimg.com/autoc.finance.yahoo.com/autoc',
            data : entity,
            dataType: 'jsonp',
            jsonp: 'callback',
            jsonpCallback: 'YAHOO.Finance.SymbolSuggest.ssCallback',
            headers : {
                'Content-Type' : 'application/json'
            },
            cache : false
        }).then(function (response) {
            return response;
        });
        return promise;     
    };
}]);