0
具體來說,我使用的是離子。我在設備準備好之前正在調用全局函數時遇到問題。如何將全局JavaScript函數中的數據移動到Angular並防止這種競爭條件?如何將全局JavaScript整合到角度?
具體來說,我使用的是離子。我在設備準備好之前正在調用全局函數時遇到問題。如何將全局JavaScript函數中的數據移動到Angular並防止這種競爭條件?如何將全局JavaScript整合到角度?
想通了。此示例特定於https://branch.io/,但它允許我使用全局JavaScript函數並使用injector()
將數據推送到角度。
聽在全球職能部門的數據,保存到一個角
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());
};
})