1

I struggling how to handle response from VSTS API in typescript.

Is there a way to handle this interface?

export interface Fields {
'System.AreaPath': any;

'System.TeamProject': string;
'System.IterationPath': string;
'System.WorkItemType': string;
'System.State': string;
'System.Reason': string;
'System.AssignedTo': string;
'System.CreatedDate': Date;
'System.CreatedBy': string;
'System.ChangedDate': Date;
'System.ChangedBy': string;
'System.Title': string;
'Microsoft.VSTS.Feedback.ApplicationType': string;
'System.Description': string;
'System.History': string;
'Microsoft.VSTS.Feedback.ApplicationStartInformation': string;
'Microsoft.VSTS.Feedback.ApplicationLaunchInstructions': string;
}

In my code i try to loop out Fields (workItems === Fields)

     <tbody>
        <tr *ngFor="let workitem of workItems">
          <!-- *ngFor="let field of workitems.fields" -->
          <td>{{workitem.fields.System.AreaPath}} << THIS IS NOT ALLOWED</td>
        </tr>

      </tbody>

Any one got a brilliant idea how to solve this?

1
  • item.fields['name.with.dots'] Commented Sep 1, 2017 at 13:03

3 Answers 3

3

{{ workitem.fields['System.AreaPath'] }}

works?

Sign up to request clarification or add additional context in comments.

Comments

1

First, you can't use ngFor on an object.

Second, if workItems is of type Fields, you don't need any loop to display one of its attributes. All you need, just like in JavaScript or TypeScript, is

workItems['System.AreaPath']

3 Comments

the ngFor section that you mention is commented
@Jota.Toledo no, it's not. I quote: "workItems === Fields" [...] <tr *ngFor="let workitem of workItems">"
You are right, but still is not clear what data type is workItems. I guess op should update his question.
0

Thanks to @elzoy and @JB Nizet it was that ['System.AreaPath'] i needed when properties on interface is "complex". I really missing some decorators in typescript like c# [JsonProperty] like. But this works great.

MANY thanks - was hours wasted before you helped me. :)

      <tbody>
        <tr *ngFor="let workitem of workItems">

          <td>{{workitem.fields['System.AreaPath']}}</td>
        </tr>
      </tbody>


export interface Fields {

'System.AreaPath': string;

'System.TeamProject': string;
'System.IterationPath': string;
'System.WorkItemType': string;
'System.State': string;
'System.Reason': string;
'System.AssignedTo': string;
'System.CreatedDate': Date;
'System.CreatedBy': string;
'System.ChangedDate': Date;
'System.ChangedBy': string;
'System.Title': string;
'Microsoft.VSTS.Feedback.ApplicationType': string;
'System.Description': string;
'System.History': string;
'Microsoft.VSTS.Feedback.ApplicationStartInformation': string;
'Microsoft.VSTS.Feedback.ApplicationLaunchInstructions': string;
}

export interface WorkItemFullInformation {
id: number;
rev: number;
fields: Fields;
url: string;

}

export interface FetchWorkItemRootObject {
count: number;
value: WorkItemFullInformation[];

}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.