I'm new to angular, no problems with a simple angular apps, but now I want to integrate with a third party component. I can think of a few kluges to achieve what I'm trying to do, but I'd prefer to use a clean solution to the general requirement: how to call angular code from "outside" angular?
I want my angular application to initialise a splash view, then wait for the third-party software to initialise and then have angular show the main view. The third-party software initialises via various asynchronous calls, and might take a second or two, or in extreme cases longer. It provides a call-back function that will be called when it's ready.
So right now to simulate the effect I have got:
.controller('MySplash', ['$scope', '$location', '$q',
function($scope, $location, $q) {
$scope.waitForInit = $q.defer();
$scope.waitForInit.promise.then(function() {
$location.path('/tab/MyMainView');
});
$scope.waitForInit.resolve(); // fake the post-init triggering
}])
So this shows the splash screen and when the deferred is satisfied shows the main screen, in this case of course it happens immediately.
I also have a function provided by the third-party software
CalledWhenThirdPartyReady() {
// put some code here
}
And in concept all I want to do is move that resolve call into this callback
CalledWhenThirdPartyReady() {
$scope.waitForInit.resolve();
}
Fundamentally, my puzzle is how to get some code that is effectively stand-alone have access to DI. In concept all I want to do is call an angular service, or access an angular variable. I've tried this kind of thing
CalledWhenThirdPartyReady() {
angular.module('myApp')
.run(["$rootScope", "$location",
function ($rootScope, $location) {
// just to show access to DI-ed variables
console.log("Run in module", $rootScope, ",", $location);
}] );
}
Thinking that the run method would be called and I'd have access to the injected variables, but run never gets triggered I guess because I'm registering the run() too late.