Angular 4应用程序中,我有一个输入文本框,其中的值必须从模板存储到json数据,im将其用作模拟数据库。我已经在下面编写了服务和保存功能,但无法将其保存在中。json文件。想法或帮助它工作。
<ng-container *ngFor="let data of displayReasonCodes$ | async;let i = index">
<tr class= "row-break">
<td>
<form>
<form-group>
<textbox [readOnly]="isEditable" ngModel="{{data .ReasonCode}}" name="textbox" ></textbox>
</form-group>
</form>
</td>
<td>
<form>
<form-group>
<textbox [readOnly]="isEditable" ngModel="{{data .Description}}" name="textbox1" ></textbox>
</form-group>
</form>
</td>
services.ts
@Injectable()
export class CodesService{
constructor(private httpClient:HttpClient, private apiUrlService : ApiUrlService){}
createReasonCodes(data:IReasonCodes){
var url = this.apiUrlService.getPostfix("/Codes");
return this.httpClient.post<IPostHttpResponse>(url,codes);
}
COMPONENT.TS
save(){
let newreasoncodeDefinition: IReasonCodes = this.poolModel.get();
this.rCodesActions.createCodes(newreasoncodeDefinition).
subscribe(definitionResponse => {
if(definitionResponse.responseCode ===1 ){
console.log("The ReasonCode " + newreasoncodeDefinition.ReasonCode + "Created Successfully");
}
})
}
ReasonCode fromUIModel.ts
poolModel: ReasonCodeFormUIModel;
ngOnInit (){
this.poolModel = new ReasonCodeFormUIModel();
public get() :IReasonCodes {
let reasonCodes = new ReasonCodes();
reasonCodes.Code= this.reasoncode;
reasonCodes.Description = this.description;
return reasonCodes;
}
}