Desidero visualizzare l'avviso Bootstrap quando l'utente ha salvato i dati.Visualizzazione dell'avviso di bootstrap utilizzando angular2
il mio codice è il seguente:
pagina HTML:
<div class="alert alert-success" *ngIf="saveSuccess">
<strong>Success!</strong>
</div>
<form #f="ngForm" (submit)="saveUser(f.value)">
/////Some form fields
<button class="form-control btn btn-primary" type="submit">save</button>
</form>
app.component.ts:
export class UserProfileComponent{
saveSuccess: boolean;
user: IUser;
saveUser(user:IUser) {
this.headers = new Headers();
this.headers.append('Content-Type', 'application/json');
this.editUserForm = user;
this._http.post('api/user/'+this._current_user._id, JSON.stringify(this.editUserForm),{
headers: this.headers
}).subscribe(function(data) {
// if the update is successful then set the value to true
// this is getting updated
if (data){
this.saveSuccess = true;
}
else{
this.saveSuccess = false;
}
});
}
}
voglio visualizzare l'avviso quando un il POST ha successo.
Penso che mi manca come associare la variabile 'saveSuccess' in html in modo che possa essere visualizzato un avviso quando il salvataggio ha avuto successo. (Sono nuovo di Angular2)
guarda bene a me - ciò che non funziona? Qualche errore nella console? – rinukkusu
Nessun errore. Non penso che darà errore. Poiché la variabile "saveSuccess" viene aggiornata e dipende dal fatto che verrà visualizzato "div". – Pradeepb
@Pradeepb Questo metodo non funziona per me. Puoi condividere il plunker se possibile? –