Reputation: 3405
Using Ionic v1 and trying to call a function from within a factory using this
or self
but getting error message:
Uncaught TypeError: Object #<Object> has no method 'connectArd'
Code:
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;
});
Upvotes: 0
Views: 170
Reputation: 1260
you must call hardwareService.connectArd(MACdevicex)
.
Since you are assigning function to hardwareService object , you must call it from there.not from factory scope
Upvotes: 1