Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 角度引导按钮点击功能_Angular_Typescript - Fatal编程技术网

Angular 角度引导按钮点击功能

Angular 角度引导按钮点击功能,angular,typescript,Angular,Typescript,我正在使用我的模板的一个简单形式。在表单中已经添加了一个验证,我只需要检查当用户点击按钮后所有必填字段怎么可能 <section class="contact-area pb-80" style="margin-top:10%"> <div class="container"> <div class="section-title"> <h2>Your Information</h2>

我正在使用我的模板的一个简单形式。在表单中已经添加了一个验证,我只需要检查当用户点击按钮后所有必填字段怎么可能

<section class="contact-area pb-80" style="margin-top:10%">
    <div class="container">
        <div class="section-title">
            <h2>Your Information</h2>
            <div class="bar"></div>
            <p>Please provide the correct information we will contact you with your information.</p>
        </div>

        <div class="row h-100 justify-content-center align-items-center">
            <div class="col-lg-6 col-md-12">
                <img src="assets/img/1.png" alt="image">
            </div>

            <div class="col-lg-6 col-md-12">
                <form id="contactForm">
                    <div class="row">
                        <div class="col-lg-12 col-md-12">
                            <div class="form-group">
                                <input type="text" name="name" id="name" class="form-control" required placeholder="Enter your name">
                            </div>
                        </div>

                        <div class="col-lg-12 col-md-12">
                            <div class="form-group">
                                <input type="email" name="email" id="email" class="form-control" required placeholder="Enter your email">
                            </div>
                        </div>

                        <div class="col-lg-12 col-md-6">
                            <div class="form-group">
                                <input type="text" name="phone_number" id="phone_number" required class="form-control" placeholder="Enter your number (Whats app)">
                            </div>
                        </div>

                        <div class="col-lg-12 col-md-6">
                            <div class="form-group">
                                <input type="text" name="msg_subject" id="msg_subject" class="form-control" required placeholder="Enter your skype name">
                            </div>
                        </div>


                        <div class="col-lg-12 col-md-12">
                            <button type="submit" class="btn btn-primary">Send Message</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</section>
如果在按钮上添加
(单击)=“submit()”
,则每次用户单击时都会调用该函数。我希望在填充所有字段后,此函数才能工作。

内部模板:

<form #myForm="ngForm">
  <input ngModel name="name" type="text" required />
  <input ngModel name="email" type="email" required />
  <input ngModel name="phone-number" type="text" required />

  <button (click)="onSubmit(myForm)">Submit</button>
</form>
确保已将
FormsModule
导入模块:

import { FormsModule } from '@angular/forms';

@NgModule({
  // ...
  imports: [..., FormsModule, ...],
  // ...
})
内部模板:

<form #myForm="ngForm">
  <input ngModel name="name" type="text" required />
  <input ngModel name="email" type="email" required />
  <input ngModel name="phone-number" type="text" required />

  <button (click)="onSubmit(myForm)">Submit</button>
</form>
确保已将
FormsModule
导入模块:

import { FormsModule } from '@angular/forms';

@NgModule({
  // ...
  imports: [..., FormsModule, ...],
  // ...
})

重要提示:
从'@angular/forms'导入{FormsModule}编码到应用程序模块中,并将其添加到导入阵列中

@NgModule({
  imports: [FormsModule],
})
在表单元素中创建一个模板变量,如下面和按钮标记上给出的
myForm
,使用属性绑定
[disabled]=“!myForm.form.valid”
。现在,提交按钮仅在填写每个表单元素时起作用

模板文件:

    <form #myForm="ngForm" method="POST" (ngSubmit)="submitForm(myForm)">
  <div>
    <label>Name</label>        
    <input name="name" type="text" required ngModel/>
  </div>
  <div>
    <label>Email</label>
    <input name="email" type="email" required ngModel/>
  </div>
  <div>
    <label>Phone no</label>
    <input name="phone" type="number" required ngModel/>
  </div>

  <button type="submit" [disabled]="!myForm.form.valid">Submit</button>
  <pre>{{myForm.value | json}}</pre>
</form>

名称
电子邮件
电话号码
提交
{{myForm.value | json}

您可以在

上找到我的代码片段。重要提示:
从'@angular/forms'导入{FormsModule}编码到应用程序模块中,并将其添加到导入阵列中

@NgModule({
  imports: [FormsModule],
})
在表单元素中创建一个模板变量,如下面和按钮标记上给出的
myForm
,使用属性绑定
[disabled]=“!myForm.form.valid”
。现在,提交按钮仅在填写每个表单元素时起作用

模板文件:

    <form #myForm="ngForm" method="POST" (ngSubmit)="submitForm(myForm)">
  <div>
    <label>Name</label>        
    <input name="name" type="text" required ngModel/>
  </div>
  <div>
    <label>Email</label>
    <input name="email" type="email" required ngModel/>
  </div>
  <div>
    <label>Phone no</label>
    <input name="phone" type="number" required ngModel/>
  </div>

  <button type="submit" [disabled]="!myForm.form.valid">Submit</button>
  <pre>{{myForm.value | json}}</pre>
</form>

名称
电子邮件
电话号码
提交
{{myForm.value | json}

您可以在

上找到我的代码片段,这不是一个角度形式。。。?我会研究角度反应形式。是的,它不是简单的引导形式,但用于角度。你想要的是在反应形式中很容易。这不是角度形式。。。?我会研究角度反应形式。是的,这不是简单的引导形式,而是在角度中使用。你想要的是在反应形式中很容易。