0

While creating object of a class, how to pass string array object as an argument into constructor of the class.

export class ManagerComponent {
    private selectedFilters: SelectedFilters;
    public ngOnInit() {
        this.selectedFilters = new SelectedFilters(new String[]);
    }
}

export class SelectedFilters {
    constructor(public related: String[]) { }
}

1 Answer 1

1

To initialize an array just use [ values ]:

this.selectedFilters = new SelectedFilters(['Test']); // Array with a string
this.selectedFilters = new SelectedFilters([]); // Empty array
Sign up to request clarification or add additional context in comments.

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.