Issue with AngularJs app in IE11: Error message "Object does not have 'then' method"

Encountering an error in IE that says: "TypeError: Object doesn't support property or method 'then'", while trying to execute the following function within my AngularJs controller:

GetUserAccessService.checkForValidHashPeriod()
    .then(function (result) {
        if (result === 'false') {
            GetUserAccessService.returnUserHashAuthentication();
        }
    });

Here's the implementation of the

GetUserAccessService.checkForValidHashPeriod
function from my AngularJs service:

this.checkForValidHashPeriod = function () {
    var result;
    var now = new Date().getTime();
    if ($sessionStorage.userAuthenticationTokenDate !== null && $sessionStorage.userAuthenticationTokenDate !== undefined) {
        var timeDiff = now - $sessionStorage.userAuthenticationTokenDate;
    }
    if (angular.isUndefined($sessionStorage.userAuthenticationToken) || timeDiff > 1500000) {
        result = false;
    }
    else {
        result = true;
    }
    var stringResult = result.toString();
    return stringResult;
};

Seeking guidance on what could be causing the issue with using a .then call?

Answer №1

Your code snippet needs to be modified because the method will now return a string and cannot utilize 'then' in this context

Var someString = GetUserAccessService.checkForValidHashPeriod()
    if (someString === 'false') {
        GetUserAccessService.returnUserHashAuthentication();
    }

Answer №2

If you're planning on implementing promises in Internet Explorer, consider using the Bluebird library to ensure compatibility with older browser versions.

Answer №3

If someone else encounters the same issue, here is an alternative solution (which I ultimately decided to use) that was inspired by feedback and guidance from Phil:

this.checkForValidHashPeriod = function () {
    var result = $q.defer();
    var now = new Date().getTime();
    if ($sessionStorage.userAuthenticationTokenDate !== null && $sessionStorage.userAuthenticationTokenDate !== undefined) {
        var timeDiff = now - $sessionStorage.userAuthenticationTokenDate;
    }
    if (angular.isUndefined($sessionStorage.userAuthenticationToken) || timeDiff > 1500000) {
        result.resolve(false);
    }
    else {
        console.log('Hash is valid.')
        result.resolve(true);
    }
    return result.promise;
};

Although some may argue it's an unnecessary use of promises and $q, I personally find this method aligns well with the approach in the rest of my service.

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

Changing the opacity of the background when a Bootstrap modal is displayedHere's how you can

While working with a bootstrap modal, I noticed that the background content opacity does not change by default when the modal is open. I attempted to change this using JavaScript: function showModal() { document.getElementById("pageContent").style.opaci ...

Ways to reset the input field of Material UI

I'm encountering an issue with clearing a form that I created using Material UI. Despite searching for solutions on Stackoverflow, none of them seem to work for me. Using setState did not achieve the desired result of clearing the form. I am looking ...

Mongod is experiencing some issues with its functionality

Every time I try to run my node app with MongoDB, I keep encountering the following error messages: body-parser deprecated bodyParser: use individual json/urlencoded middlewares server.js:32:9 body-parser deprecated undefined extended: provide extended op ...

Display and conceal fields based on radio button selection using JavaScript

Hello, I have a specific scenario that I need assistance with. In my code, I have a div container that contains 3 radio buttons with IDs "rad1", "rad2", and "rad3". Additionally, I have a form with 2 text fields that have IDs "textField1" and "textField2". ...

Steps to access a JSON file in Angular.JS locally without utilizing a server

Below is the code for my controller: angular.module('navApp', []).controller('blogCtrl', function($scope, $http) { $http.get("../json/blogs.json").success(function(response) {$scope.blogs = response.blogs;}); }); I am trying to fi ...

Incorporate live Twitch streaming onto a web platform

I'm currently in the process of making a website for a friends twitch stream and I'm very confused as to how I implement the twitch stream. I have created a div with the class "Twitchscreen" but I have no idea how I link to the twitch API or get ...

Loading Collada files with a progress callback function can help track the

Is there a proper way to incorporate a loading bar while using the ColladaLoader? The code indicates that the loader requires three parameters, with one being a progressCallback. progressCallback( { total: length, loaded: request.responseText.length } ); ...

Updating $route parameter in AngularJS - the ultimate guide

I have a variety of routes that differ, but share similar parameters. For instance: when '/user/:accountId/charts/:chartType', controller:ChartsController when '/manager/:accountId/charts/:chartType', controller:ChartsController when ...

Tips for showcasing a Bootstrap alert

I'm attempting to integrate Bootstrap Alerts into my project, but I'm struggling to display them programmatically. Here is the HTML snippet: <div class="alert alert-success alert-dismissible fade show" role="alert" id="accepted-meal-al ...

Unable to open new tab using target _blank in React js production build

After attempting to access the link, a 404 error appeared in the live version of react js and triggered an error on the firebase hosting platform. <Link target='_blank' to={'/property-details?id='some_id'}/> ...

Delays in running multiple jQuery UI effects at the same time

When I implement a show and hide effect with slide on different divs simultaneously on my page, I encounter some lag in the animation. However, I noticed that if I run the show effect only after the hide effect is completed, the lag disappears. I am curiou ...

UI-Router - Displaying and concealing elements dynamically in response to state changes

I am currently dealing with a situation where I have implemented dynamic showing and hiding of a button based on state changes. However, there seems to be a noticeable delay when the button is supposed to hide. The button itself is created as a directive ...

Diagnosing circular JSON can be a challenging task

Encountering an issue in my error handler with the following message: Uncaught TypeError: Converting circular structure to JSON. I suspect that there might be an additional exception thrown within the JSON.stringify call leading to this error. It's p ...

Only object types can be used to create rest types. Error: ts(2700)

As I work on developing a custom input component for my project, I am encountering an issue unlike the smooth creation of the custom button component: Button Component (smooth operation) export type ButtonProps = { color: 'default' | 'pr ...

Backand.com experienced a surprise encounter with an error 404 while utilizing the REST API

Working with my web app, I've integrated Backand.com as my MBAAS provider. All tables are linked and a data model has been set up. While querying the default REST APIs poses no issue, encountering a 404 error randomly happens when attempting to call ...

Displaying JSON data in a browser using Node.js without the need for refreshing the page

I am currently working on a node.js server that fetches JSON data from an external source and displays it in a browser window. I need assistance in setting up an automatic update every minute to reflect any changes in the JSON without requiring a manual re ...

A guide to filtering out items from observables during processing with RxJS and a time-based timer

I have a complex calculation that involves fetching information from an HTTP endpoint and combining it with input data. The result of this calculation is important for my application and needs to be stored in a variable. async calculation(input: MyInputTy ...

Modify HTML text using conditional CSS without JavaScript

Apologies for asking such a beginner question, but I've searched high and low for a similar post, to no avail. Here's my query: I have a paragraph text in my HTML code that I want to automatically replace with new text when I click a specific B ...

Having trouble showing an image with jQuery after it has been uploaded

Currently, I have a URL that shows an image upon loading. However, I want to provide the option for users to replace this image using a form input. My goal is to display the uploaded image as soon as it's selected so users can evaluate it. I'm a ...

The method of inserting a JSON dates object to deactivate specific days

I am currently utilizing a date picker component that can be found at the following link: While attempting to use the disabledDays section below, I have encountered an issue where I am unable to apply all three options. The blockedDatesData option works o ...