Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/276.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 为后角点添加实体数据4_Angular - Fatal编程技术网

Angular 为后角点添加实体数据4

Angular 为后角点添加实体数据4,angular,Angular,我正在将输入元素中的内容添加到正文请求中。因此,我可以根据成员Id和合作伙伴Id提取数据,我尝试了很多没有运气的事情,希望能得到帮助。我想使用双向数据绑定和模板驱动的表单 我已经准备好了FormsModule。 这是密码 从'@angular/core'导入{Component,OnInit}; 从'@angular/Http'导入{Http}; 导入'rxjs/add/operator/map'; 常量guid=函数(){ 返回s4()+s4()+'-'+s4()+'-'+s4()+'-''

我正在将输入元素中的内容添加到正文请求中。因此,我可以根据成员Id和合作伙伴Id提取数据,我尝试了很多没有运气的事情,希望能得到帮助。我想使用双向数据绑定和模板驱动的表单 我已经准备好了FormsModule。 这是密码

从'@angular/core'导入{Component,OnInit};
从'@angular/Http'导入{Http};
导入'rxjs/add/operator/map';
常量guid=函数(){
返回s4()+s4()+'-'+s4()+'-'+s4()+'-''+
s4()+'-'+s4()+s4()+s4()+s4();
};
函数s4(){
返回Math.floor((1+Math.random())*0x10000)
.toString(16)
.子串(1);
}
@组成部分({
选择器:“应用程序数据”,
templateUrl:'./data.component.html',
样式URL:['./data.component.css']
})
导出类DataComponent实现OnInit{
memberId='SVR17066GYA';
partnerId=101;
构造函数(公共http:http){}
getMembers(){
//常量bodyGetInfo={
//“PartnerId”:this.PartnerId,
//“MemberId”:this.MemberId,
//“产品”:“默认值”,
//“CorrelationId”:guid()
// };
常量bodyGetInfo={
“PartnerId”:this.PartnerId,
“MemberId”:this.MemberId,
“产品”:“默认值”,
“CorrelationId”:guid()
};
返回此.http.post('url')
.map(res=>res.json());
}
恩戈尼尼特(){
这是getMembers()
.订阅(会员=>{
控制台日志(成员);
})
}
}

{{memberId}

{{partnerId}
那么您想设置服务器对html输入的响应


首先,您要在ngInit中发送请求,我猜您希望在填写完表单并单击submit按钮后发送请求,因此您需要从submit按钮发送一个post on(click)事件,您需要将其添加到html中。如果我弄错了,请更正。

那么您想将服务器的响应设置为html格式的输入


首先,您要在ngInit中发送请求,我猜您希望在填写完表单并单击submit按钮后发送请求,因此您需要从submit按钮发送一个post on(click)事件,您需要将其添加到html中。如果我弄错了,请纠正我。

好的,我找到了答案,我想我会发布适用于模板驱动表单的新代码。我将在下一步建立反应式表单,并在得到它后发布。希望这对其他人有帮助:)

从'@angular/core'导入{Component};
从'@angular/Http'导入{Http};
常量guid=函数(){
返回s4()+s4()+'-'+s4()+'-'+s4()+'-''+
s4()+'-'+s4()+s4()+s4()+s4();
};
函数s4(){
返回Math.floor((1+Math.random())*0x10000)
.toString(16)
.子串(1);
}
@组成部分({
选择器:“应用程序数据”,
templateUrl:'./data.component.html',
样式URL:['./data.component.css']
})
导出类数据组件{
memberId:string;
partnerId:编号;
构造函数(公共http:http){
}
提交(f){
console.log(f.value.memberId);
console.log(f.value.partnerId);
this.memberId=f.value.memberId;
this.partnerId=f.value.partnerId;
常量bodyGetInfo={
“PartnerId”:this.PartnerId,
“MemberId”:this.MemberId,
“产品”:“默认值”,
“CorrelationId”:guid()
};
返回此.http.post('url')
.订阅(res=>{
console.log(res.json())
});
}
}

提交

好的,我想我会发布适用于模板驱动表单的新代码。我将在下一步建立反应式表单,并在得到它后发布。希望这对其他人有帮助:)

从'@angular/core'导入{Component};
从'@angular/Http'导入{Http};
常量guid=函数(){
返回s4()+s4()+'-'+s4()+'-'+s4()+'-''+
s4()+'-'+s4()+s4()+s4()+s4();
};
函数s4(){
返回Math.floor((1+Math.random())*0x10000)
.toString(16)
.子串(1);
}
@组成部分({
选择器:“应用程序数据”,
templateUrl:'./data.component.html',
样式URL:['./data.component.css']
})
导出类数据组件{
memberId:string;
partnerId:编号;
构造函数(公共http:http){
}
提交(f){
console.log(f.value.memberId);
console.log(f.value.partnerId);
this.memberId=f.value.memberId;
this.partnerId=f.value.partnerId;
常量bodyGetInfo={
“PartnerId”:this.PartnerId,
“MemberId”:this.MemberId,
“产品”:“默认值”,
“CorrelationId”:guid()
};
返回此.http.post('url')
.订阅(res=>{
console.log(res.json())
});
}
}

提交

谢谢您的回答。我希望实现的是在向表单添加数据时发送请求,而不使用提交按钮,但是,我可以看到,这也会导致另一组问题,即在表单中键入每个字符时,输入都会发送。我将按建议添加一个提交按钮:)谢谢您的回答。我希望实现的是在向表单添加数据时发送请求,而不使用提交按钮,但是,我可以看到,这也会导致另一组问题,即在表单中键入每个字符时,输入都会发送。我将按建议添加提交按钮:)