从组件访问index.html中的branch.init()-Angular 6

时间:2019-01-18 09:10:18

标签: javascript angular branch

我在index.html页面中添加了脚本标记,该标记将branch.io添加到了我的应用中。现在,如何在需要使用branch.link()创建Deeplink的组件中访问它?

组件路径:app / routes / create-deeplink

这是索引中的脚本标签:

<script>
      // load Branch
      (function(b,r,a,n,c,h,_,s,d,k){if(!b[n]||!b[n]._q){for(;s<_.length;)c(h,_[s++]);d=r.createElement(a);d.async=1;d.src="https://cdn.branch.io/branch-latest.min.js";k=r.getElementsByTagName(a)[0];k.parentNode.insertBefore(d,k);b[n]=h}})(window,document,"script","branch",function(b,r){b[r]=function(){b._q.push([r,arguments])}},{_q:[],_v:1},"addListener applyCode autoAppIndex banner closeBanner closeJourney creditHistory credits data deepview deepviewCta first getCode init link logout redeem referrals removeListener sendSMS setBranchViewData setIdentity track validateCode trackCommerceEvent logEvent disableTracking".split(" "), 0);
      // init Branch
      branch.init('live-key-goes-here');
  </script>

在我的组件中,我需要具有以下内容:

generateDeeplink() {
        // this object is from their documentation
        const linkData = {
            campaign: 'content 123',
            channel: 'facebook',
            feature: 'dashboard',
            stage: 'new user',
            tags: [ 'tag1', 'tag2', 'tag3' ],
            alias: '',
            data: {
                'custom_bool': true,
                'custom_int': Date.now(),
                'custom_string': 'hello',
                '$og_title': 'Title',
                '$og_description': 'Description',
                '$og_image_url':'http://lorempixel.com/400/400'
            }
        };
        // this is what I need, how to access branch?
        branch.link(linkData, function(err, link) {
            console.log(link);
        });

0 个答案:

没有答案