2016-11-02 24 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()); 
    }; 
})