I'm trying to call a function from my dataservice factory but it throws an error Cannot read property 'login' of undefined
Here is my dataservice factory
(function(){
'use strict';
// dataservice factory
angular
.module('app')
.factory('dataservice', dataservice);
dataservice.$inject = ['$http'];
function dataservice($http) {
return {
login : login
}
function login(username, password, callback) {
$http.post('/data', { username: username, password: password })
.success(function (response) {
console.log(response);
});
}
}
})();
Here is my controller
(function(){
'use strict';
angular
.module('app')
.controller('TestController', TestController);
TestController.$inject = ['dataservice'];
function TestController(dataservice) {
var vm = this;
vm.login = login;
function login() {
console.log('is this called?');
vm.loading = true;
dataservice.login(vm.username, vm.password, function (result) {
console.log(result);
});
}
}
})();
login function it is called when i press login from view , since i get: is this called? in my console.