Home global variables typescript not defined
Reply: 2

global variables typescript not defined

Bistaff
1#
Bistaff Published in 2017-12-07 12:49:32Z

I have a problem with typescript global variable.

I'm writing a piece of code to login with facebook in my ionic 3 app.

I have a global variable declared, but when the app runs, got me the error *.*FB is not defined** at the function FB.init({})

The code:

//all needed imports

declare const FB;

@Injectable()
export class AuthenticationProvider implements OnInit{

  //properties

  //constructor

   ngOnInit() {
     debugger
     if( FB != null && FB != 'undefined')
     {
       FB.init({
         appId: '***',
         cookie: false,access
         status: true,
         xfbml: true,
         version: 'v2.11'
       });
     }
   }

   //FB.login(){} inside an observable function
   //FB.getLoginStatus(){} inside an observable function
   //FB.api(){} inside an observable function

 }

Can someone help me?

Hugo Noro
2#
Hugo Noro Reply to 2017-12-07 12:59:42Z

In TypeScript const is a block scoped variable. For a true global variable you need to use var.

sancelot
3#
sancelot Reply to 2017-12-07 13:17:27Z

Your FB api has not been correctly imported in your application.

this must be something similar as

import * as FB from 'fb_api';

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.300735 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO