0

I have successfully load my dynamic JSON Object to my template, but what I'm trying to do is format dynamic result from JSON Object here is my template:

<tr *ngFor="let row of searchResult">
 <td *ngFor=" let key of keys; let i = index;">
                {{row[key]}}
              </td>
</tr>

and on my script i have received the data from web API that's contains the data to JSON Object

this.keys = Object.keys(this.searchResult[0]);

now some of JSON Values needs to be formated,depends on it's content One field can contain Dates and other can contain links and other can contain number , ... etc

How should i deal with this data formats dynamically ? How to identify the specifec type in the loop below

{{row[key]}}

sample JSON Object

[{"FIELD_1":"713071A","X_KYC_FULL_NAME_EN":"Atef","CASE_TYPE_CD":"CASETYPECD","PRIORITY_CD":"M","CREATE_DTTM":"2016-07-18 12:03:21.627","INVESTIGATOR_USER_ID":"user1","CASE_ID":"FATCA-2016-16095-1","CASE_CATEGORY_CD":null,"CASE_RK":16098,"X_KYC_FULL_NAME_AR":"صالح","CASE_STATUS_CD":"CBCSD"},{"FIELD_1":"713071B","X_KYC_FULL_NAME_EN":"Yasser","CASE_TYPE_CD":"CASETYPECD","PRIORITY_CD":"M","CREATE_DTTM":"2016-07-18 12:03:21.65","INVESTIGATOR_USER_ID":"user1","CASE_ID":"FATCA-2016-16095-2","CASE_CATEGORY_CD":null,"CASE_RK":16099,"X_KYC_FULL_NAME_AR":"صالح","CASE_STATUS_CD":"CBCSD"},{"FIELD_1":"713071C","X_KYC_FULL_NAME_EN":"Ahmed","CASE_TYPE_CD":"CASETYPECD","PRIORITY_CD":null,"CREATE_DTTM":"2016-07-18 12:03:21.673","INVESTIGATOR_USER_ID":"user1","CASE_DESC":null,"CASE_ID":"FATCA-2016-16095-3","CASE_CATEGORY_CD":null,"CASE_RK":16100,"X_KYC_FULL_NAME_AR":"احمد","CASE_STATUS_CD":"CBCSD"}]
  • https://stackoverflow.com/questions/35754586/how-to-format-date-as-dd-mm-yyyy-in-angular-2-using-pipes – floor Mar 23 '18 at 19:56
  • You can have a look at this question which does the same thing using pipes: https://stackoverflow.com/questions/35534959/access-key-and-value-of-object-using-ngfor?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa – edkeveked Mar 23 '18 at 20:01
  • I have seen these questions before, but my issue is that the keys and values are dynamics, nothing static , sometime the result can contain 2 fields and sometime it may content 5 or X fields ( Everything is dynamic ) so i can't identify when should i use the specific format for date, number or any other specific format ** The answer that you suggest can be used when you have fixed template – Ahmed Bagalaty Mar 23 '18 at 20:21
  • I believe that Dynamic forms in Angular can help, – Ahmed Bagalaty Sep 04 '21 at 18:50
  • I found a lot of resources later that will help https://stackoverflow.com/questions/59281460/angular-8-dynamic-form-from-json https://angular.io/guide/dynamic-form – Ahmed Bagalaty Sep 04 '21 at 18:52

0 Answers0