0
具体的には、Ionicを使用しています。私はデバイスが準備が整う前に呼び出されているグローバル関数に問題があります。グローバルなjavascript関数からのデータをAngularに移動し、この競合状態を防ぐにはどうすればよいですか?グローバルなJavaScriptを角度に統合するにはどうすればよいですか?
具体的には、Ionicを使用しています。私はデバイスが準備が整う前に呼び出されているグローバル関数に問題があります。グローバルなjavascript関数からのデータをAngularに移動し、この競合状態を防ぐにはどうすればよいですか?グローバルなJavaScriptを角度に統合するにはどうすればよいですか?
これがわかりました。この例は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());
};
})