使用離子v1和嘗試使用this
或self
從工廠內部調用一個函數,但得到錯誤信息:廣東話呼叫服務方法(使用離子)
Uncaught TypeError: Object #<Object> has no method 'connectArd'
代碼:
angular.module('hardware.services', [])
.factory('hardwareserv', function($http,$rootScope,$state,$cordovaBluetoothSerial) {
var hardwareService = {};
hardwareService.connectArd = function(MACaddress) {
window.bluetoothSerial.connect(MACaddress, this.successConnect2, this.failConnect);
};
this.connectArd(MACdevicex); // calling above method
return hardwareService;
});
稱它爲我沒有看到'hardwareService'任何地方所定義。這段代碼沒有顯示'this'等於'hardwareService' – devqon
很抱歉忘了添加,但是用var hardwareService = {}定義了它。 – condo1234