Angular 4 应用程序,我有一个输入文本框,其中值必须从模板存储到 json 数据,我用作模拟数据库。我在下面编写了服务和保存功能,但没有将其保存在 .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;
}
}