I'm building a sign up form, which will submit a user's input and then transit to a logged in state with template specific to this new user.
As far as I understand, to do this I have to use ng-submit() in html template together with $state.go() in controller.
Template:
<form ng-submit="register(name, password)">
...
<input class="btn btn-success btn-lg btn-block" type="submit" value="Sign Up">
</form>
Controller:
angular.module('myApp').controller('RegisterController',
['$scope','userService', function($scope, userService) {
$scope.register = function(name, passed) {
userService.register(name, passed);
$state.go("app.home");
}
}])
However, there are only a few places I need to use $state.go(), in most cases, ui-sref in the html template is sufficient. Is this mixing of ui-sref and $state.go() a good practice? According to ui-router document, they essentially do the same thing. But with the state transition scattered in two different places (template and controller), it feels like a code smell to me.
I tried to use ui-sref and ng-submit together but it doesn't work, ng-submit gets ignored. What is the best practise in this case?