split is not a function




Asked on May 13, 2024
In my Angular application, I am converting comma separated values into array using split() method.

countryForm = this.formBuilder.group({
    selectedCountry: ''
});

get selectedCountryAsArray() {
    return this.countryForm.get('selectedCountry')?.value?.split(',');

It is throwing error.

ERROR TypeError: this.countryForm.get(...).value.split is not a function

    
    
  



Replied on May 13, 2024
Use toString()

get selectedCountryAsArray() {
    this.countryForm.get('selectedCountry')?.value?.toString().split(',');
}




Replied on May 13, 2024
Got it. Thanks.

Write Answer












©2024 concretepage.com | Privacy Policy | Contact Us