Using Facebook SDK in Angular 2

后端 未结 3 1763
别那么骄傲
别那么骄傲 2021-01-04 10:42

I\'ve been reading this: https://developers.facebook.com/docs/sharing/reference/share-dialog

and I need to import the facebook SDK in order to use the following code

3条回答
  •  甜味超标
    2021-01-04 11:18

    If you want to get access inside your any.component.ts file you'll need get a window referece (Iam using the follwing code):

    function _window():any {
      return window;
    }
    
    export class WindowRef {
        public static get():any {
            return _window();
        }
    }
    

    Now you can:

    import { WindowRef } from './windowRef';
    
    export class AnyComponent {
       WindowRef.get().FB.ui // <-- this is how you'll reference it now
    }
    

    You'll need to make sure, that the FB Object is availabe on window. Afterwards your code will transpile.

提交回复
热议问题