これは、これは私のHTML部分であるデータベースにAngular2を使用してModalのデータを更新するにはどうすればよいですか?
export class UserprofileComponent
{
getdata : string;
public data;
Username : any ;
Firstname :any;
updateuser(){
let re = /[?&]([^=#&]+)=([^&#]*)/g;
let match;
let isMatch = true;
let matches = {};
while (isMatch)
{
match = re.exec(window.location.href);
if (match !== null)
{
matches[decodeURIComponent(match[1])] = decodeURIComponent(match[2]);
if (match.index === re.lastIndex)
{
re.lastIndex++;
}
}
else {
isMatch = false;
}
}
console.log(matches);
var headers= new Headers({'Content-Type' : 'application/x-www-form-urlencoded '});
var body = JSON.stringify({
username1 : this.user.Username,
firstname1 : this.user.Firstname,
})
this.http.post('../widgets/Update.php?ID='+matches['ID'],body, {
headers:headers; })
.map(res => res.json())
.map(res => {
if(res.success)
{
this.m=res.Message;
}
else{
this.m="wrong";
}
})
.subscribe(
data =>this.getdata = JSON.stringify(data),
err => console.error(err),
() => console.log('done'));
}
}
更新データのための私のAngular2 part.Here Updateuser
関数である。ここでは
<ngl-modal header=" Edit Profile" [(open)]="opened" [size]="size">
<div body>
<div class="form-horizontal" style="margin:auto;" id="editForm" *ngFor="#user of getdata">
<div class="form-group">
<label class="col-md-3 control-label">Username:</label>
<div class="col-md-8">
<input type="text" class="form-control" id="cname" [(ngModel)]="user.Username" />
</div>
</div>
<div class="form-group">
<label class="col-md-3 control-label">Firstname:</label>
<div class="col-md-8">
<input type="text" class="form-control" id="ads" [(ngModel)]="user.Firstname"/>
</div>
</div>
<span>{{m}}</span>
<button class="slds-button slds-button--neutral" (click)="cancel()">Cancel</button>
<button class="slds-button slds-button--neutral slds-button--brand" (click)="updateuser()">Save</button>
</ngl-modal>
私がすることによって表示されたデータを表示するためのモーダルを使用したいですngForce.Butこの表示データを更新する方法は?データはngModelによって表示され、ngModel
の値をとっている場合は、たとえば[(ngModel)]="user.name"
の場合、ユーザーが何をすべきかを定義していないというエラーが表示されます。この場合??
私はベータ版を使用しているので、あなたの最初の推測のためには、その#を許さないようにしなければなりません。そして、あなたの3番目の推測のために、あなたが提案した方法では動作しません。あなたの応答のためにありがとうございます。@ bolanren –
こんにちは、これまでのところそれを動作させることができましたか? – bolanren
いいえ、私は何も管理していませんでした。 –