Доступ к branch.init () в index.html из компонента - угловой 6 - PullRequest
0 голосов
/ 18 января 2019

Я добавил тег script на свою страницу index.html, который добавляет branch.io в мое приложение. Теперь, как я могу получить к нему доступ в моем компоненте, где мне нужно создать deeplink, используя branch.link()?

Путь к компоненту: приложение / маршруты / создание-глубокая ссылка

Вот тег скрипта в индексе:

<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);
        });
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...