Chcę wyświetlić alert Bootstrap, gdy użytkownik zapisał dane.Wyświetlanie alertu ładowania początkowego za pomocą metody angleular2
mojego kodu jest jak poniżej:
stronie 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;
}
});
}
}
chcę wyświetlić alert gdy zakończono pomyślnie test POST.
Myślę, że brakuje mi powiązania zmiennej "saveSuccess" z html, dzięki czemu można wyświetlić alert po pomyślnym zapisaniu. (Jestem nowy w Angular2)
wygląda dobrze do mnie - co nie działa? Jakieś błędy w konsoli? – rinukkusu
Brak błędów. Nie sądzę, że da błąd. Ponieważ zmienna "saveSuccess" jest aktualizowana i zależy od tego, "div" zostanie wyświetlony. – Pradeepb
@Pradeepb Ta metoda nie działa dla mnie. Czy możesz podzielić się plunkerem, jeśli to możliwe? –