I am working on Angular 1.6.9
. I have used jsonp
method to get my response. My response is callback function. I am using .success()
function in angular 1.4.9
and I am able to parse my Jsonp callback response successfully. Here I have attached my working js fiddle.
http://jsfiddle.net/sathees552/m7hh3362/
I am using angular 1.6.9
, but since .success()
method is deprecated, I am using .then()
function instead, as well as $sce.trustAsResourceUrl(url)
. But I am no longer able to parse my response. Its giving below error
Uncaught ReferenceError: projectInstance is not defined
I have defined projectInstance
in my controller, still it's not recognized. But the same method I was using in angular 1.4.9
was working fine. Here I have attached my plunker link which is not working
https://plnkr.co/edit/TidicooyborGTGHvUzJK?p=preview
My Html code:
<div ng-app="myapp" ng-controller="personCtrl">
<button ng-click="doRequest()">Make JSONP request</button>
</div>
My js code:
var app = angular.module('myapp', []);
app.config(function($sceDelegateProvider) {
$sceDelegateProvider.resourceUrlWhitelist([
'self',
'http://www.mocky.io/v2/**'
]);
});
app.controller('personCtrl', ['$http', '$scope', '$sce', function($http, $scope, $sce) {
$scope.doRequest = function() {
//creating
var projectInstance = {
jsonpCallback: function(commandName, responseData) {
alert(responseData.projectSnapShot[0].projectId);
}
}
var url = "https://www.mocky.io/v2/5ac61eed4a000061007e065b";
var trustedUrl = $sce.trustAsResourceUrl(url);
$http.jsonp(trustedUrl, {
jsonpCallbackParam: 'jsonpCallback'
}).then(function(data) {
eval(data)
}, function(error) {
console.log(error);
return error;
})
};
}]);
My Response :
projectInstance.jsonpCallback("getActiveProduct",{"totalRecords":null,"projectSnapShot":[{"projectId":"333333","projectNumber":"123456","projectStatus":"Active"}]})