我在Angular中有一个前端项目,其中有一个带有数据列表的Html文件和另一个后端项目Restful API 如何从Angular的数据列表中获取选定的选项并将其值发送到我的其余服务器。我用玻璃鱼。我想以JSON格式阅读。 这是我已经尝试使用的一些代码。
private Json computeDiff(Json a, Json b) {
Json ret = Json.object();
for (String key : b) {
if (a.hasKey(key)) {
Object aVal = a.getObject(key);
Object bVal = b.getObject(key);
if (aVal instanceof Json && ((Json) aVal).isObject()) {
Json innerJson = computeDiff((Json) aVal, (Json) bVal);
if (innerJson.size() > 0) {
ret.with(key, innerJson);
}
} else {
if (aVal.equals(bVal)) {
continue;
}
ret.with(key, b.getObject(key));
}
} else {
ret.with(key, b.getObject(key));
}
}
for (String key : a) {
if (!b.hasKey(key)) {
// this element got deleted
ret.with(key, "<DELETED>");
}
}
return ret;
}
export class OrganizeComponent implements OnInit {
@ViewChild('f') form: NgForm;
restaurant = {
naam: '',
adres: ''
};
constructor(private router: Router, private http: HttpClient) { }
ngOnInit() {
}
onOrganize(form: NgForm) {
this.restaurant.naam = this.form.value.naam;
this.restaurant.adres = this.form.value.adres;
this.http.post('http://localhost:8080/testproject/resources/restaurant', {
naam: this.restaurant.naam,
adres: this.restaurant.adres})
.subscribe(
res => {
console.log(res);
},
err => {
console.log('Error occured');
}
);
}
btnClick1= function () {
this.router.navigateByUrl('/menu');
};