I am trying to insert data in mongoose using angularjs and node js. For this i have created a factory where i am calling another js file where i have created my database connect
You cannot inject $scope to factory. Services do not have scopes. Only Controllers.
So you have to use something like this.
test.factory('registrationservice', function($http){
var factory = {};
// if user is another service you have to inject it in factory defenotion function
// and delete from here.
facotry.newregister = function(user, $scope) {
var newUser = new user({
username: $scope.uName,
firstname: $scope.fName,
lastname: $scope.lName,
email:$scope.mail,
password: $scope.newpwd
});
return $http.post('data/registration.js', newUser);
}
return factory;
});
And then in your controller.
test.controller('registrationCtrl', function($scope, $log, registrationservice){
registrationservice.newregister(user, $scope).success(function(msg){
$log.info(msg.data);
})
});