【发布时间】:2016-06-14 18:09:29
【问题描述】:
我对 Angular 很陌生,并且在进行同步操作时遇到了问题。我已经解决了 Angular 控制器遇到的一些问题,我从 newController 文件中收到错误“无法调用未定义的方法”。
angular.module('newApp.newController', ['angularSpinner', 'ui.bootstrap'])
.controller('newController', function($q, $scope, utilityFactory, $http) {
utilityFactory.getData().then(function(data) {
console.log("success");
console.log(data);
});
});
angular.module('newApp.utility', [])
.factory('utilityFactory', function($q, $http) {
var utils = {};
//This is a cordova plugin
var getLauncher = function() {
return window.plugin.launcher;
};
var success = function(data) {
console.log(device);
return device;
}
var fail = function(error) {
console.log("error", error);
};
utils.getData = function() {
/* Get the store number details initially before initalizing the application */
if (window.plugin) {
var launcher = getLauncher();
console.log("Fetching data from device");
//Cordova js is returning this method
return launcher.getDevice(success, fail);
}
};
return utils;
})
【问题讨论】:
-
getData没有返回任何东西 -
我也用过这个 return launcher.getDevice(success, fail);
-
但是
else不会返回任何东西,launcher.getDevice会返回什么? -
Launcher.prototype.getDevice = function(successCallback, failureCallback) { exec(successCallback, failureCallback, KEY, 'getDevice', []); };
-
'launcher.getDevice' 从 android 手机如 macId 返回设备相关信息
标签: javascript angularjs promise