Make sure to allow the async task to complete before beginning with Angular JS

As I develop an app using MobileFirst v8 and Ionic v1.3.1, I encounter issues with timing in my code execution. Specifically, when the application initiates, the regular ionic angular code within my app.js file runs.

This section of the code handles the initialization:

.run(function($ionicPlatform) {
  $ionicPlatform.ready(function() {
    ...
  })
.controller('IndexCtrl', function($scope, $state) {
    RememberMeService.checkIfLoggedIn().success(function(data) {
        alert("YAY!!");
    }).error(function(data) {
        alert('fail :(');
    });

});

function wlCommonInit() {
var serverUrl = WL.App.getServerUrl(function(success){
    console.log(success);
}, function(fail){
    console.log(fail);
});

WLAuthorizationManager.obtainAccessToken().then(
    function (accessToken) {
        console.log(">> Success - Connected to MobileFirst Server");       
    },
    function (error) {
        console.log(">> Failed to connect to MobileFirst Server");  
        console.log(error);        
    }
);

The following snippet represents the RememberMeService:

.service('RememberMeService', function($q) {
return {
    checkIfLoggedIn: function() {
        var deferred = $q.defer();
        var promise = deferred.promise;
        var securityCheckName = 'UserLogin';

        WLAuthorizationManager.obtainAccessToken(securityCheckName).then(
                function (accessToken) {
                    console.log('USER IS LOGGED IN!!!');
                },
                function (response) {
                    console.log("obtainAccessToken onFailure: " + JSON.stringify(response));
            }
        );

        promise.success = function(fn) {
            promise.then(fn);
            return promise;
        }
        promise.error = function(fn) {
            promise.then(null, fn);
            return promise;
        }

        return promise;

    }
}
})

An issue arises when the RememberMeService is invoked, resulting in a failure at the line where

WLAuthorizationManager.obtainAccessToken(securityCheckName).then
is called due to it stating that WLAuthorizationManager is not defined. This occurs because the asynchronous function wlCommonInit() from app.js has not completed yet.

How can I implement a delay in either the controller or service being executed until wlCommonInit() completes, and WLAuthorizationManager is defined?

Your assistance is greatly appreciated.

EDIT

Below is the updated wlCommonInit() function:

function wlCommonInit() {
var serverUrl = WL.App.getServerUrl(function(success){
    console.log(success);
}, function(fail){
    console.log(fail);
});

WLAuthorizationManager.obtainAccessToken().then(
    function (accessToken) {
        console.log(">> Success - Connected to MobileFirst Server"); 
        angular.bootstrap(document.getElementById('indexBody'), ['app']);
    },
    function (error) {
        console.log(">> Failed to connect to MobileFirst Server");  
        console.log(error);        
    }
);

Here is the corresponding segment from my index.html:

<body id="indexBody">
    <h1>test</h1>
</body>

Upon implementation, an error message is displayed:

kError in Success callbackId: WLAuthorizationManagerPlugin887134242 : Error: [$injector:modulerr] Failed to instantiate module ng due to:
TypeError: Cannot set property 'aHrefSanitizationWhitelist' of null

Is there any flaw in how I am attempting to bootstrap the application?

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Creating an outlined effect on a transparent image in a canvas: step-by-step guide

Currently, I am working on creating transparent images using canvas in HTML5 and I would like to incorporate borders into them. The issue I'm facing is that the "Stroke" property does not consider the transparency of the image and applies it as if it ...

The call stack size has been exceeded in Next.js, resulting in a RangeError

Currently attempting to deploy my project on vercel.com but encountering an error specifically with 3 pages that have no internal errors. An error occurred while prerendering the page "/applications". For more information, visit: https://nextjs.org/docs/me ...

What is the best way to fully eliminate the Pixi renderer, stage, and all associated assets

I am currently faced with a challenge of mounting and unmounting a Pixi stage using React without relying on react-pixi. Upon re-mounting the component, I encounter the following error: Uncaught Error: Resource with name "cupCake.png" already exists i.ad ...

The Slice method is malfunctioning after the array has been filtered

I am currently working on creating a news portal app using Next JS, Redux, mongoose, and Express. My Issue is: While I am able to filter specific items from an array successfully, I encounter problems when attempting to display a specific number of items, ...

"Enhancing Code Functionality in React - Seeking Ways to Improve

When working with Redux, I often find myself repeatedly using the same piece of code: const dispatch = useDispatch() Then, every time I need to call a function, I do something like this: dispatch(endpointError(true)) My goal is to streamline this proce ...

Methods to prompt a user to select an option using Bootstrap

I have been struggling with this problem for hours and it's really starting to frustrate me! Currently, I am incorporating Twitter Bootstrap along with bootstrap-min.js. This is the code snippet in question: <select id="assettype" name="assettyp ...

glitch in animation when quickly mousing over and out

How can I resolve an animation glitch that occurs when quickly hovering over and then off an element? You can view the live version of the website at - Whenever I rapidly hover on and off the circle, it starts acting buggy. It happens consistently, so I& ...

Having difficulty rendering Twitter Bootstrap glyphicons correctly

While following an Angular.js Todo application video tutorial, I ran into a snag trying to include Twitter Bootstrap 3 glyphicons in the index.html file. The icons were displaying as unfamiliar images in both Chrome and Firefox. Here is how I am adding th ...

Activate Bootstrap datetimepicker by using the enter key to automatically populate the initial date

Check out the Bootstrap datetimepicker on this page: I'm trying to make it so that when the datetimepicker is first shown, pressing the enter key will hide the widget and insert the current date into the input field. I've experimented with a few ...

I desire to activate the textbox only when the radiobtnlist value equals 1

I am trying to disable a textbox based on the selected value of a RadioButtonList in my code. However, the functionality is not working as expected and I am unsure why. <script type="text/javascript"> $(function () { $("#RadioButton ...

Initiate the month transition event within the fomantic calendar

In my project, I have integrated the fomantic calendar and it is working properly. However, I am facing an issue when it comes to changing the month. Is there a specific event for month changes in the fomantic calendar? I am struggling to make it work. Tha ...

The function given to requestAnimationFrame is not being triggered as expected

I have successfully implemented an infinite loop animation using setInterval. However, I want to enhance the performance by switching to requestAnimationFrame(). Unfortunately, the function supplied to requestAnimationFrame() is not being called for some r ...

Understanding the functionality of $exceptionHandlerIn order to fully

While exploring angularjs, I discovered a method to manage uncaught exceptions using the built-in $exceptionHandler service. As stated in the documentation, I am manually handling exceptions by incorporating try {...} - catch(e). Below is an example: try ...

There was an error in locating the JavaScript file within the Node.js Express Handlebars application

My website is not displaying the .js file, css file, or image from the public folder. Here are the errors showing up in the console: GET http://localhost:8080/assets/images/burger.jpg 404 (Not Found) GET http://localhost:8080/burgers.js net::ERR_ABORTED ...

Using Angular NgUpgrade to inject an AngularJS service into an Angular service results in an error message stating: Unhandled Promise rejection: Cannot read property 'get' of undefined; Zone:

I have noticed several similar issues on this platform, but none of the solutions seem to work for me. My understanding is that because our Ng2App is bootstrapped first, it does not have a reference to $injector yet. Consequently, when I attempt to use it ...

Issue with RegisterClientScriptCode function following a partial postback

In a SharePoint website, the code below is contained within a user control: ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "jquery144", "<script type=\"text/javascript\" src=\"/_layouts/Unicre.Web.RUOnline.Controlos/Script ...

How to Show Firestore Query Results in a React Native App

I'm struggling to correctly manage the synchronization, asynchronization, and promises related to querying Firestore. Let me simplify my scenario for you. I have different categories of items and I want to display all the categories along with their r ...

Attempting to send arguments to a jQuery ajax request

After successfully implementing my original ajax call, I decided to create a reusable function for it. This way, I can easily modify the data and URL fields of the ajax call without having to retype everything each time. However, I encountered an issue whe ...

Deactivate CS:GO Dedicated Server using Node.js child_process

I've been attempting to manage multiple Counter Strike: Global Offensive dedicated servers programmatically. The process is running smoothly, however, I am facing a challenge in shutting it down completely. Upon starting the server, two processes are ...

JS script for clicking various icons on a webpage that trigger the opening of new tabs

I am working on a webpage where I have 9 icons with the same class. I am trying to write JavaScript code that will automatically open all 9 icons when the webpage loads. I tried using the code below, but it only clicks on the first icon and stops. let ...