我想在打字稿文件中单击按钮时发布json数据
这是打字稿文件
{
type: 'button',
id: 'save',
className: 'btn btn-primary save-template',
events: {
click: evt => {
_this.save();
(<any>config).opts.onSave(evt, _this.data.formData);
this.formData = new FormData();
this.formData.append("Form", JSON.stringify(_this.data.formData));
this.dataService.addItem(this.formData).subscribe(
data => {
});
}
}
}].concat(options.actionButtons);
这是我的服务
addItem(data: FormData) {
const postForm = new HttpRequest('POST', `${this.API_URL}/FormTemplates/PostFormTemplate`, data, {
reportProgress: true
});
return this.httpClient.request(postForm);
}
我遇到的错误是无法读取未定义的属性'addItem'
修改
save(stage = null) {
let _this = this;
let data = this.data;
if (!stage) {
stage = this.d.stage;
}
let doSave = {
xml: () => _this.xmlSave(stage),
json: () =>
(<any>window).JSON.stringify(_this.prepData(stage), null, '\t')
};
// save action for current `dataType`
data.formData = doSave[(<any>config).opts.dataType](stage);
// trigger formSaved event
document.dispatchEvent(events.formSaved);
return data.formData;
}