astrakid932
astrakid932

Reputation: 3405

Cant call service method in Angular factory (using Ionic)

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

Answers (1)

Nikhil Mohanan
Nikhil Mohanan

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

Related Questions