Currently, I am in the process of constructing a sign-up form that will collect user input and then transition to a logged-in state with a template tailored specifically for this new user.
To achieve this, my understanding is that I need to utilize ng-submit()
in the HTML template along with $state.go()
in the controller.
Here's how the code looks:
<form ng-submit="register(name, password)">
...
<input class="btn btn-success btn-lg btn-block" type="submit" value="Sign Up">
</form>
And here is the controller implementation:
angular.module('myApp').controller('RegisterController',
['$scope','userService', function($scope, userService) {
$scope.register = function(name, password) {
userService.register(name, password);
$state.go("app.home");
}
}])
Although, I have noticed that I only require using $state.go()
in a few instances, since most cases can be handled by using ui-sref
in the HTML template. Is it considered good practice to mix ui-sref
and $state.go()
? While both essentially accomplish the same goal as per the ui-router documentation, having state transitions split between two different areas (template and controller) seems like it may lead to code smell.
I attempted combining ui-sref
with ng-submit
, but unfortunately, the ng-submit
was disregarded. So, what would be the recommended approach in this scenario?