Navigator and windows error with typescript angular 2

I am trying to use ng2-translate in my ionic 2 app using:

this.translateService.setDefaultLang('en');
            if (this.platform.is('cordova')) {
                if (navigator.globalization) {
                    navigator.globalization.getPreferredLanguage(function (language) {

      

but i am getting this error

Typescript Error
Property 'globalization' does not exist on type 'Navigator'.
src/app/app.component.ts
if (this.platform.is('cordova')) {
    if (navigator.globalization) {

      

And I have the same error with window.cordova

in this line of code:

if (this.platform.is('cordova') && window.cordova.plugins.Keyboard) {

      

Should I declare the type of navigator or something else?

thanks for the help

0


source to share


1 answer


You are missing the Typescript information input for this navigator object. Basically, the error you are seeing is the Typescript compiler saying that based on the type definitions you have provided so far, there is no information that the object navigator

has a property globalization

.

The solution is to add information to enter this navigator object.

I honestly don't know which package contains these type definitions, but from Typescript v2 (or v2.1 ... can't remember which one), npm stores type definitions for Typescript libraries in the @types namespace.

So you want



npm install --save-dev @types/<some package>

      

to add type definitions to your project.

I would suggest starting with:

@npm install --save-dev @types/cordova-ionic 

      

0


source







All Articles