我想在用户保存数据时显示Bootstrap警报.
我的代码如下:
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; } }); }
}
我想在POST成功完成后显示警报.
我想我错过了如何将’saveSuccess’变量绑定到html,以便在成功保存完成后显示警报. (我是Angular2的新手)