Il mio errore è,angolare 2: 'ngFormModel' dato che non è una proprietà nativa noto
EXCEPTION: Error: Uncaught (in promise): Template parse errors:
non può legarsi a 'ngFormModel' dato che non è una proprietà nativa noto ("
MIO PROFILO] [ngFormModel] = "forma" (ngSubmit) = "onSubmit (form.value)">
"): una @ 3: 7 non v'è alcuna direttiva con "exportAs" set a "ngForm" ("stname ] # Firstname = "ngForm">
"): una @ 9: 85 Non v'è alcuna direttiva con "exportAs" impostato su "ngForm"("/label> ] # cognome = "ngForm">
mio modello,
<h3 class = "head">MY PROFILE</h3>
<form [ngFormModel]="form" (ngSubmit)="onSubmit(form.value)">
<div class="row">
<div class="form-group">
<label class="formHeading">firstname</label>
<input type="text" id="facebook" class="form-control" ngControl="firstname" #firstname="ngForm" >
</div>
<div *ngIf ="firstname.touched">
<div *ngIf ="!firstname.valid" class = "alert alert-danger">
<strong>First name is required</strong>
</div>
</div>
<div class="form-group">
<label class="formHeading">lastname</label>
<input type="text" id="facebook" class="form-control col-xs-3" ngControl="lastname" #lastname="ngForm" >
</div>
<div *ngIf ="lastname.touched" >
<div *ngIf = "!lastname.valid" class = "alert alert-danger">
<strong>Last name is required</strong>
</div>
</div>
<div class="form-group">
<label class="formHeading">Profilename</label>
<input type="text" id="facebook" class="form-control col-xs-3" ngControl="profilename" #profilename="ngForm" >
</div>
<div class="form-group">
<label class="formHeading">Phone</label>
<input type="text" id="facebook" class="form-control col-xs-3" ngControl="phone" #phone="ngForm" >
</div>
<div *ngIf ="phone.touched" >
<div *ngIf = "!phone.valid" class = "alert alert-danger">
<strong>Phone number is required</strong>
</div>
</div>
<label class="formHeading">Image</label>
<input type="file" name="fileupload" ngControl="phone">
<div class="form-row btn">
<button type="submit" class="btn btn-primary " [disabled]="!form.valid">Save</button>
</div>
</div>
</form>
mio Component, importazione {Component} da '@ angolare/core'; import {Http, Response, Headers} da '@ angular/http'; importare {Observable} da 'rxjs/Observable'; importare {Subject} da 'rxjs/Subject'; importare {contentHeaders} da "../headers/headers"; importare {FORM_DIRECTIVES} da "@ angular/forms"; importare {Router, ROUTER_DIRECTIVES} da '@ angular/router'; importare {Control, FormBuilder, ControlGroup, Validators} da '@ angular/common';
@Component({
templateUrl: './components/profile/profile.html',
directives: [ROUTER_DIRECTIVES,FORM_DIRECTIVES],
})
export class Profile {
http: Http;
form: ControlGroup;
constructor(fbld: FormBuilder,http: Http,public router: Router) {
this.http = http;
this.form = fbld .group({
firstname: ['', Validators.required],
lastname: ['', Validators.required],
profilename :['', Validators.required],
image : [''],
phone : [''],
});
}
onSubmit(form:any){
console.log(form);
let body = JSON.stringify(form);
var headers = new Headers();
this.http.post('http://localhost/angular/index.php/profile/addprofile',body,{headers:headers})
.subscribe(
response => {
if(response.json().error_code ==0){
alert('added successfully');
this.router.navigate(['/demo/professional']);
}
else{
alert('fail');
}
})
}
}
Le domande di aiuto per il debug ("perché non funziona questo codice?") Devono includere il comportamento desiderato, un problema specifico o un errore e il codice più breve necessario per riprodurlo nella domanda stessa. Le domande senza una chiara affermazione di problemi non sono utili agli altri lettori. Vedi: Come creare un esempio Minimo, Completo e Verificabile. –
Sei sicuro di utilizzare l'ultimo @ angular/forms 0.2.0 con rc.4? Nella tua vista c'è 'ngControl', che non è più usato. Ho inserito il tuo modello in questo [plunker] (http://plnkr.co/edit/uiYZkEWMyXWOkglHZu6N) e funziona correttamente. – robisim74
Inoltre tutte le importazioni per il modulo nel componente stanno importando da 'common' e non dal nuovo' forms'. Vedi https://angular.io/docs/ts/latest/guide/forms.html. – robisim74