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());
};
})