Angular2没有击中Api

时间:2017-06-15 18:04:33

标签: angular2-forms

在这里我试图从ang2击中我的Api为什么它没有击中。即使我的小提琴手也没有高速流量,请检查我的代码

 constructor(private fb: FormBuilder, private _http: Http) {     
        _http.get('http://localhost:40039/Api/Home/GetEmp').subscribe(result => {
            this.ctstArrayList = result.json();
        }
        )}
    doSubmit(): Observable<Customer> {

              let headers = new Headers({ 'Content-Type': 'application/json' });
            let options = new RequestOptions({ headers: headers });
            return this._http.post('http://localhost:40039/Api/Home/SaveEmp', JSON.stringify(this.custobj), options)
                    .map(this.extractData)
                    .catch(this.handleError);        
            }  

这是我的html代码,我实现了ngtoch和其他一些验证 Html代码

<form class="form-horizontal" novalidate (ngSubmit)="doSubmit()" [formGroup]="customerForm">

                <fieldset>
                    <div class="form-group" [ngClass]="{'has-error': (customerForm.get('EmpName').touched ||
                                                  customerForm.get('EmpName').dirty) &&
                                                    !customerForm.get('EmpName').valid }">

                        <label for="name">Name</label>
                        <input type="text" class="form-control" formControlName="EmpName" [(ngModel)]="custobj.EmpName" />
                        <span>Hell{{custobj.EmpName}}</span>
                        <span class="help-block" *ngIf="(customerForm.get('EmpName').touched ||
                                                         customerForm.get('EmpName').dirty) &&
                                                         customerForm.get('EmpName').errors">
                            <span *ngIf="customerForm.get('EmpName').errors.required">
                                Please enter your first name.
                            </span>
                            <span *ngIf="customerForm.get('EmpName').errors.minlength || customerForm.get('EmpName').errors.maxlength">
                                The first name must be longer than 3 and max6 characters.
                            </span>
                        </span>
                    </div>
   <button type="submit" class="btn btn-success btn-block" (click)="doSubmit(custobj)" [disabled]="!(customerForm.valid)">Submit</button>

0 个答案:

没有答案