Open SasiMallow opened 8 years ago
@SasiMallow I've also found that the readme examples with then/catch don't work, I think it's because ng-submit="submitRegistration(registrationForm)"
doesn't use your controller and instead goes straight to ng-token-auth.
I do something like this, which I find gives me the flexibility I want.
<form role="form" ng-init="registrationForm = {}" >
<div >
<label>email</label>
<input type="email" name="email" ng-model="registrationForm.email" required placeholder='example@mail.com' ng-model-options="{ updateOn: 'blur' }"/>
<div style="color: red" ng-show="registrationForm.email.$error.required && submitted ">Email required.</div>
<span ng-show="registrationForm.email.$error.required">Email is required.</span>
</div>
<div class="form-group">
<label>password</label>
<input type="password" name="password" ng-model="registrationForm.password" required ng-minlength="8" ng-model-options="{ updateOn: 'blur' }"/>
<div style="color: red" ng-show="registrationForm.password.$error.minlength">minimum 8 characters.</div>
</div>
<div class="form-group">
<label>password confirmation</label>
<input type="password" name="password_confirmation" ng-model="registrationForm.password_confirmation" required/>
</div>
<button type="submit" class="btn btn-primary btn-lg" ng-click="doRegister()">Register</button><br>
<a ng-href="#/">Login</a>
</form>
app.controller('RegisterCtrl',['$scope', '$location', '$auth', function($scope, $location, $auth){
console.log('signup controller');
$scope.doRegister = function(){
$auth.submitRegistration($scope.registrationForm)
.then(function(resp) {
alert("Registration success");
console.log("response");
console.log(resp);
// handle success response
})
.catch(function(resp) {
console.log(resp);
// handle error response
});
};
}]);
Anyway, I hope this help you.
@dgoradia Its working fine. Thank you.
I am using devise-token-auth in rails backend and ng-token-auth in angularJs. I am calling rails API from angularJs. I have added all configuration and submitting the form but i cannot get response from
submitRegistration
method. Is there any mistake i my code?console.log(resp);
doesn't print any response.