全局变量打字稿未定义

时间:2017-12-07 12:49:32

标签: angular facebook typescript facebook-graph-api ionic-framework

我对typescript全局变量有疑问。

我正在编写一段代码,以便在我的离子3应用程序中使用facebook登录。

我声明了一个全局变量,但是当应用程序运行时,得到错误*。* FB未定义**函数 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

 }

有人可以帮助我吗?

2 个答案:

答案 0 :(得分:0)

在TypeScript中,const是一个块范围的变量。对于真正的全局变量,您需要使用var。

答案 1 :(得分:0)

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

这必须与

类似

import * as FB from 'fb_api';

相关问题