简体   繁体   中英

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.

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.

A few more details...I'm using a bootstrap tabset (ui-bootstrap, to be specific). 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.

Typescript

  @Input() formName: ngForm;

HTML

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

DEMO

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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