1

Need to find the locale and pass the same to service(get) call :

Property 'indexOf' does not exist on type '() => string[]'

Heading

in angular4.

//Call Languages 
getshortLanguages() {      
        return new Array('en', 'es', 'fr', 'it', 'pt', 'de', 'ru', 'tr', 'ko', 'ja', 'zh-cn', 'zh-hk');
    }

    getLocale() {
        const locale = this.dbservice.getSessionContext().locale.toLowerCase();
        var Languages = this.getshortLanguages;
        if (!locale) return 'en';     
        var languageCode = locale.split('-')[0].toLowerCase();    
        if (this.getshortLanguages.indexof(languageCode)>-1 ) {
            return languageCode;
        }
        else return 'en';
    }
1
  • That should be this.getshortLanguages().indexOf(languageCode) you are missing the open/close () which calls the method getshortLanguages(). Otherwise you are returning the method without calling it. Commented Oct 23, 2019 at 10:33

1 Answer 1

1

You are most probably trying to use a getter right?

In order to do this, you need to separate the get from the name like this:

//Call Languages 
get shortLanguages() {      
    return new Array('en', 'es', 'fr', 'it', 'pt', 'de', 'ru', 'tr', 'ko', 'ja', 'zh-cn', 'zh-hk');
}

getLocale() {
    const locale = this.dbservice.getSessionContext().locale.toLowerCase();
    var Languages = this.getshortLanguages;
    if (!locale) return 'en';     
    var languageCode = locale.split('-')[0].toLowerCase();    
    if (this.shortLanguages.indexof(languageCode)>-1 ) {
        return languageCode;
    }
    else return 'en';
}

Otherwise, you should got the way Igor Mentioned. In your case the getShortLanguages without the parentheses () is nothing more than the definition of your function and not an array at all.

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.