[英]How to implement Angular 1 Form with Component and custom validation
I want to implement an angular form that holds a custom component and that uses custom (asynchronous) validation. 我想实现一个包含自定义组件并使用自定义(异步)验证的角度形式。
I was not able to find any documentation on how to implement that based on angular components. 我找不到任何有关如何基于角度组件来实现的文档。
The link function used with the "normal" directive examples is not available for components. 与“普通”指令示例一起使用的链接功能不适用于组件。 The documentation https://code.angularjs.org/1.5.1/docs/guide/forms does only explain how to do this with directives (requiring ngModel and using it in the link function).
文档https://code.angularjs.org/1.5.1/docs/guide/forms仅说明了如何使用指令(要求ngModel并在链接函数中使用它)执行此操作。
How would I do this with angular components? 我该如何使用角度组件呢?
I was also looking for this and ended up here: [ https://github.com/angular-ui/ui-validate] . 我也在寻找它,并最终到达了这里:[ https://github.com/angular-ui/ui-validate] 。
I find this less invasive anyway, but it doesn't work for encapsulating validation with the element as well. 无论如何,我发现这种方法的侵入性较小,但是对于将验证与元素封装在一起也不起作用。 In those cases I think you will still want to go with a directive as angular's guidelines themselves seem to suggest to use directives where link functions are needed.
在这些情况下,我认为您仍然会希望使用指令,因为angular的准则本身似乎建议在需要链接功能的地方使用指令。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.