문제

I'd like to know if there's other options for form validation other than using directives.

Mixing your validation (business) with the view is not what I call separation-of-concerns and it seems validation support is too primitive in angular world.

I'm used to working with knockout and want something like knockout-validation. Validation rules there are set in the view-model, complete and clean separate from the view. Is there any comparable lib to that ?

Thanks.

도움이 되었습니까?

해결책

You could use ng-change events and then call your validator service.

You can set fields invalid using the $scope.formName.inputName.$setValidity method, pass the form to your validation service and you're good to go.

https://code.angularjs.org/1.2.16/docs/api/ng/type/ngModel.NgModelController

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top