I have this "model" in TypeScript 2:
export class MyModel {
myProperty1: string;
myProperty2: string;
...
}
I also have this class:
// Leaving out the imports
@Component
...
export class MyClass {
private myArray: Array<MyModel>;
ngOnInit() {
this.myArray = ...// calls a service which returns a populated array of MyModel objects;
}
ngAfterViewInit() {
var newArray: Array<string> = this.myArray ??? // take only myProperty1 from myArray objects and assign to newArray
}
}
How can I take only the myProperty1 in myArray and assign to my new string array?
So if myArray contains two elements of type MyModel:
[{"one", "apple"}, {"two", "oranges"}]
Then newArray should end up containing these two elements of type string:
["one", "two"]