简体   繁体   English

将表格传递给表格之外的指令

[英]Pass form to directive that lives outside of the form

I've looked up to 10 pages deep on Google and can't find and answer to this one...so hopefully, there IS one. 我在Google上浏览了多达10页,找不到并回答了这一页...因此,希望有一页。

I would like to access a form (specifically, it's validity) from outside of the form. 我想从表单外部访问表单(特别是有效性)。 I've seen and implemented the use of require: '^form' which works great for when the directive is inside the form. 我已经看到并实现了require:'^ form'的用法,当指令位于表单内部时,该方法非常有用。

A few more details...I'm using a bootstrap tabset (ui-bootstrap, to be specific). 其他一些细节...我正在使用引导程序选项卡集(具体来说是ui-bootstrap)。 The idea is to change the tab header text when the form in the tab content panel is valid. 其想法是在选项卡内容面板中的表单有效时更改选项卡标题文本。 Each tab has it's own form. 每个选项卡都有其自己的形式。

Any help is appreciated! 任何帮助表示赞赏!

Thanks, Wayne 谢谢,韦恩

Failing to have your working demo, I assumed some aspects of the issue. 由于没有您的工作演示,我假设了问题的某些方面。 If you set a variable on the form and pass that name to the directive via an @Input, you can have access to that form inside the directive. 如果您在表单上设置变量,然后通过@Input将名称传递给指令,则可以在指令内部访问该表单。

Typescript 打字稿

  @Input() formName: ngForm;

HTML 的HTML

  <form #f="ngForm"></form
....
  <div [formName]="f" .....> 

DEMO 演示

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM