全局变量未定义



我有打字稿全局变量的问题。

我正在编写一件代码以在我的Ionic 3应用中使用Facebook登录。

我有一个全局变量声明,但是当应用程序运行时,我的错误*。*fb并未在function fb.init({})

上定义** **。

代码:

//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
 }

有人可以帮我吗?

typeScript const中的范围是块范围的变量。对于真正的全局变量,您需要使用VAR。

您的FB API尚未在您的应用程序中正确导入。

这一定是类似的

import * as FB from 'fb_api';

最新更新