Insert a run section into AngularJS 1.3.8

Looking to integrate a run block into the AngularJS 1.3.8 code snippet below?

After several attempts, I noticed that when I include the run block in my Angular app, the browser debugger in FireFox shows that the program briefly pauses at the beginning of the run block before proceeding through the other sections like module, config, and controllers. Eventually, the app fails to load altogether. However, when I remove the run block, the Angular application functions correctly.

This code is adapted from a sample app, with the only modification being the addition of the run block.

angular.module('hello', [/*'ngCookies',*/ 'ngRoute']).config(function($routeProvider, $httpProvider) {

    $routeProvider.when('/', {
        templateUrl: 'home.html',
        controller: 'home',
        controllerAs: 'controller'
    }).otherwise('/');

    $httpProvider.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';

}).run(function ($rootScope, $cookies) {
    var cookieValue = $cookies.get("myCookie");
    if (cookieValue) {
        $rootScope.myCookieVar = cookieValue;
    }
}).controller('navigation',

function ($rootScope, $http, $location, $route) {

    var self = this;

    self.tab = function(route) {
        return $route.current && route === $route.current.controller;
    };

    $http.get('user').then(function(response) {
        if (response.data.name) {
            $rootScope.authenticated = true;
        } else {
            $rootScope.authenticated = false;
        }
    }, function() {
        $rootScope.authenticated = false;
    });

    self.credentials = {};

    self.logout = function () {
        $http.post('logout', {}).finally(function () {
            $rootScope.authenticated = false;
            $location.path("/");
        });
    }

}).controller('home', function ($http) {
    var self = this;
    $http.get('resource/').then(function(response) {
        self.greeting = response.data;
    })
});

Answer №1

$cookies did not include the get() and set() methods prior to version 1.4.

Refer to the documentation for more information.

You can experiment by switching to:

var cookieValue = $cookies.myCookie;

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

Ways to stop a webpage from auto-refreshing using JAVASCRIPT

While working on a form to submit values using AJAX and PHP, I encountered an issue where the return value of AJAX was always 0. After some investigation, I realized that the problem was caused by the page being refreshed. AJAX var xhttp = new XMLHttpRequ ...

Error Connecting to Database with Node.JS MySQL Module - ECONNRESET Issue

Attempting to establish a connection with my database using the mysql module has been quite the challenge. Each time I try, an error seems to pop up: read eCONNRESET There is problem. (The final part is from my console log, as seen below.) I've ruled ...

The custom events in jQuery PubSub based MVC are failing to trigger

I'm currently attempting to construct a PubSub based MVC design (for certain reasons). If you take a look at this specific jsFiddle link, you'll notice that none of the custom events seem to be triggering, and unfortunately, I am unable to determ ...

Creating a merged object from a split string array in TypeScript

I possess an array containing objects structured as follows; const arr1 = [ {"name": "System.Level" }, {"name": "System.Status" }, {"name": "System.Status:*" }, {"name": "System.Status:Rejected" }, {"name": "System.Status:Updated" } ] My object ...

Once all the fields are filled, I would like for my button to trigger the opening of my

I need help figuring out how to summon my modal only when all fields are filled: <form action="" id="myForm"> <fieldset> <input type="hidden" name="action" value="contact_s ...

Attempting to retrieve a value from a bespoke store in Svelte

Let me pose a question: I have created a custom store that looks like this: const MyCustomStore = (Data) => { const { subscribe, set, update } = writable(Data); return { subscribe, update, set, setData: (NewData) => { set(Ne ...

Incompatibility issues arise when trying to implement Dojo toolkit widgets in an AngularJS application

I'm currently working on integrating Dojo gauges into my AngularJS application. I know that Dojo is also a framework that follows the MVC pattern like AngularJS, but right now, I have an AngularJS app and I want to utilize existing widgets from other ...

Button from Material-UI vanishes upon being clicked

I encountered an issue with a button that disappears when clicked on. Additionally, clicking the button once does not trigger any actions associated with it. In order to execute the button actions, I have to click the area where the button was located afte ...

The PHP file is encountering issues with running the script

My code isn't functioning as intended and is supposed to dynamically add fields related to guest information. The issue lies with the Add more button not working when clicked. This form is designed for guests to fill out using MySQL, PHP, JavaScript ...

Nested AngularJS Directives

Two of my directives are called resource and formajax. Let's take a look at their implementations: Resource resource.coffee (snippet) (...) ($http, $location, $compile) -> restrict: "E" templateUrl: templateUrl sc ...

Capturing the Clicked Element's Value in Uib Pagination without Scroll to Top

For my project, I am utilizing uib pagination. I have successfully implemented a feature that allows the page to scroll to the top when a link is clicked. However, I am facing an issue where the page scrolls to the top when clicking on '...'. How ...

Issue: Unable to find a compatible version of chokidar. Attempted chokidar@2 and chokidar@3 after updating npm to version 7.*.*

After using ejected CRA, it compiled successfully but then broke with the following error. The issue started to occur after updating npm from version 6 to 7. You can now view webrms in the browser. Local: http://localhost:3001 On Your Netw ...

Tips for maintaining focus on an editable div using jQuery

Is there a way to prevent an editable div from becoming unfocused when clicking on a formatting bar created using jQuery? I've been trying to implement this feature but can't seem to figure it out. Any advice would be greatly appreciated. Many th ...

javascript popup window with redirection functionality

Hello everyone, I need assistance with the code snippet below: echo ("<SCRIPT LANGUAGE='JavaScript'> window.alert('Successfully Updated') </SCRIPT>"); I am trying to redirect the page to my edit.php after c ...

The Array Find() method keeps returning 'undefined' when trying to search for data based on URL parameters

Is there a way to display data from an array based on a specific condition? I have been attempting to do this by checking if the requested id matches any of the ids in the data array. Unfortunately, whenever I run the following code snippet, I always end u ...

Ember's structured format featuring objects as rows and column names as properties

I am currently working on developing a modular tabular form that requires an input of two arrays: one containing objects (representing the rows) and another containing property names of those objects (representing the columns). The goal is to be able to mo ...

Is it possible to connect various functions or modules using NPM in a single project?

Currently, I have a set of helper functions that I would like to make available globally in the command line. Utilizing the npm link method, I was able to achieve this by following the steps outlined in this guide: { "name": "tool1", ...

Converting Datepicker selection to a string format in AngularJS

Can anyone help me figure out how to convert a datepicker value into a string that can be passed as a parameter to a get method without causing an error? <div ng-app="getserviceApp" ng-controller="getserviceCtrl"> <button ng-click="Func ...

Is there a way to direct the embedded YouTube video on my HTML website to open in the YouTube application instead?

My website has embedded Youtube videos, but when viewing on a mobile browser they open in the default player. I want them to open in the Youtube application instead, as my videos are 360 degrees and do not work properly in the default browser player. ...

Problem with responsive design on iPhone

I'm currently working on developing a responsive chatbot using CSS Bootstrap. However, I've encountered an issue where the header and footer are not fixed when I open the app on an iPhone. The keyboard header is also moving up the screen, which s ...