我在angularjs模块中有一个工作JSONP调用来工作我定义了模块外部的回调(见下文)。我无法在模块内部进行回调(回调未定义)。
如何在角度模块中获得jsonp_callback(data)
?
function jsonp_callback(data) {
// returning from async callbacks is (generally) meaningless
alert('good');
console.log(data.found);
}
angular.module('me.services', [])
.factory('Products', ['$http', '$q', '$filter', function ($http, $q, $filter) { // Query API and return JSON.
return {
get: function () {
var _deferred = $q.defer(),
funds = [],
products = [];
var murl = "http://localhost:82/api/productlist/getitems";
$http.jsonp(murl + "?callback=jsonp_callback", null, function (result) {
alert('ts');
});
}
答案 0 :(得分:0)
取决于您希望如何处理角度内的数据:
function jsonp_callback(data) {
// for binding to a service property
angular.element(document).injector().get('ServiceName').whatever = data
// for binding to a controller scope propery
angular.element('#someDiv').scope().whatever = data
...