JSFiddle - React, Tailwind, and code Playground
HTML
<div ng-app="myApp" ng-controller="jsonp_example">
<button ng-click="doRequest()">Make JSONP request</button>
</div>
JavaScript
var myApp = angular.module('myApp',[]);
myApp.controller('jsonp_example',function($scope, $http,dataService) {
$scope.doRequest = function() {
dataService.getData(function(data){
console.log(data);
});
};
});
myApp.service('dataService', function($http) {
console.log("in service!!");
return{
getData: function(callback) {
console.log("http fn");
resp = "test";
// from here i get the syntax error
var url = "http://public-api.wordpress.com/rest/v1/sites/wtmpeachtest.wordpress.com/posts?callback=JSON_CALLBACK";
$http.jsonp(url)
.success(function(data){
console.log(data.found);
resp="success";
callback(resp);
});
}
}
});