0

I made a corresponding UI object as follows. Now the backend Target java object has a field like following. Is there any way i can define similar in Angular Target object.Is there set and Map object implementation in Angular2

Java

Not javascript

private Set<String> exportCodes = new HashSet<>();
private Map<String, Set<String>> itemDataTypeMap = new HashMap<>();

Corresponding TypeScript object

export class Target {
    constructor(
        public name?: string,
        public targetType?: string,
        public exportUrl?: string,
        public userName?: string,
        public password?: string,
    ) { }
}
14
  • 3
    Angular doesn't provide any collections. This is a pure TypeScript or JavaScript question. Commented Feb 20, 2017 at 13:36
  • I am not sure what you are asking or trying to achieve... Can you please elaborate with additional detail or a more complete example? Commented Feb 20, 2017 at 13:38
  • @GünterZöchbauer : Ah okay. Thank you. So is there any prebuild collections in typescript ? Commented Feb 20, 2017 at 13:39
  • Sorry, no idea what "rebuild collections" mean, but I'm not using TS actively myself. Commented Feb 20, 2017 at 13:39
  • @Igor : So basically how can i declare a Set in Target frontend class Commented Feb 20, 2017 at 13:41

2 Answers 2

1

There are some Set and Map classes in ES6-enabled browsers, you should just need to set the target of your tsconfig.json to ES6.

There are also polyfills for old-school browsers. like core-js

You should then be able to declare such objects like:

let foo = new Map<string,Set<string>>();
let bar = new Set<string>();

Also note that the traditional way of creating a Map<string,something> in js is to make an object that will act as an associative array, it has the advantage of being portable across old and modern browsers. You can declare this in typescript like a dictionnary:

let foo:{[k:string]:any}={}
Sign up to request clarification or add additional context in comments.

Comments

1
    I used. This works. tested

MAP

    interface Map
    var Map: MapConstructor

SET

    declare var Set: SetConstructor;

conversions might look like following. I still need to check with data.

    public exportCodes?: Set<string>,
    public itemDataTypeMap?: Map<string, Set<Item>>

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.