2016-11-02 23 views

回答

0

想通了。此示例特定於https://branch.io/,但它允許我使用全局JavaScript函數並使用injector()將數據推送到角度。

全球DeepLinkHandler成角

聽在全球職能部門的數據,保存到一個角DeepLink工廠

// a global function 
function DeepLinkHandler(data) { 
    if (data) { 
    // access the angular Factory('DeepLink') 
    angular.element(document.querySelector('[ng-app]')).injector().get('DeepLink').set(data); 
    console.log('Data Link handler response: ' + JSON.stringify(data)); 
    } else { 
    console.error('Data Link handler no data'); 
    } 
} 

DeepLink工廠

angular.module('starter.services', []) 

.factory('DeepLink', function($window, $timeout) { 
    var data = {}; 

    return { 
    get: function() { 
     return data; 
    }, 
    set: function(json) { 
     // use the angular version of timeout 
     $timeout(function() { 
     // set the data 
     data = json; 
     // navigate example 
     $window.location = "#/tab/chats/3"; 
     }, 0); 
    } 
    }; 
}); 

訪問角DeepLink

angular.module('starter.controllers', []) 

.controller('DashCtrl', function($scope, DeepLink) { 
    $scope.content = {} 
    $scope.buttonPressed = function() { 
    // put branch data into a label that has ng-model content.data 
    $scope.content.data = JSON.stringify(DeepLink.get()); 
    }; 
})