Reputation: 21
I am getting error in controller.js
controller.js
angular.module('myApp', ['ngRoute', 'ui.router']).controller('authCtl', ["$scope", "$rootScope", "loginService", function($scope, $rootScope, loginService) {
$rootScope.bodyClass = "focusedform";
$scope.submitForm = function() {
loginService.userAuth($scope.username, $scope.password);
}
}]);
factory.js
angular.module('myApp').factory('loginService', ["$http", "$q", function($http, $q) {
userFactory = {};
userAuth = function(username, password) {
console.log(username + '' + password);
};
return true;
}]);
Upvotes: 1
Views: 83
Reputation: 25352
You didn't return your object in factory.
You have to attach your methods variable in an object and return it from factory in order to access from controller.
Try like this
angular.module('warApp').factory('loginService', ["$http", "$q", function($http, $q) {
var userFactory = {};
userFactory.userAuth = function(username, password) {
console.log(username + '' + password);
};
return userFactory;
}]);
or try like this for better view
angular.module('warApp').factory('loginService', ["$http", "$q", function($http, $q) {
var userFactory = {
userAuth: userAuth
}
return userFactory;
function userAuth(username, password) {
console.log(username + '' + password);
}
}]);
Upvotes: 5