requiredSubmit is not working with ng-include
In controller, I declare this.
$scope.user =
username: ''
password: ''
submit: () ->
$validator.validate $scope, 'user'
.success () ->
Auth.signUp
username: $scope.user.username
password: $scope.user.password
.then ()->
$location.path "/helloworld"
.error ->
console.log "err"
In view
<form name="form" novalidate>
<div ng-include="'/partials/auth/sign-up-form'">
</div>
<button ng-click="user.submit()" class="btn btn-lg btn-success">Sign Up</button>
</form>
/partials/auth/sign-up-form.html
<div class="input-group form-group">
<span class="input-group-addon form-title">
<label for="username">username</label>
</span>
<input type="text" class="form-control" id="username" ng-model="user.username" placeholder="username" validator="[required, requiredSubmit]">
</div>
When I use without ng-include, well done. I have checked the user is same scope wheather using ng-include or not. I can't understand what is defferent. How to can I fix it?
Hello @victorkim I think the $scope in ng-include and the $scope at container are different.
$validator.validate $scope, 'user'
You should replace $scope as one in ng-include.
Another solution is to use a controller in the form. Controllers are better suited for this casses, than $scope itself.
Thanks for answer.
I checked angular-validator code.
The ng-include update value parent scope through user prototype. But validator event binded in ng-include's scope and triggered by container's scope.
So @kelp404 and @genuinefafa solution is should working. But I don't want making meaningless controller.
If I make some form with modal(http://angular-ui.github.io/bootstrap/), controller scope different with scope. Modal controller have only form logic. But I just add a controller for validator. This is bad for my project.
I want to find better solution.(Because I love this project and I want keep this lib in my project.)
@victorkim I understand where you are going, and I agree with you. Maybe it's time to improve the validator if no other solution is found. ;)