Programmatically adding route resolve in Angular using $routeProvider

Is it possible to dynamically add Angular's resolve after it has been initially defined in the app? Let's say we have a setup with routes like this:

app.config(['$routeProvider', function ($routeProvider) {
  $routeProvider
    .when("/", {templateUrl: "partials/home.html", controller: "PageCtrl"})
    .when("/services", {templateUrl: "partials/services.html", controller: "PageCtrl"})
}]);

Now, at a later stage, can I modify specific route(s) to include resolve for handling promises?

app.config(['$routeProvider', function ($routeProvider) {
  $routeProvider
    .when("/services", {
      templateUrl: "partials/services.html",
      controller: "PageCtrl",
      resolve:{ getData: function(myService) { return myService.getOffer(); }}
    })
}]);

I'm wondering how this can be achieved. The main challenge is adding this functionality after the initial configuration has taken place. It needs to happen sometime in the future.

Answer №1

That's correct

app.run(function ($route) {
  var route = $route.routes['/...'];
  route.resolve = route.resolve || {};
  route.resolve.someResolver = ...;
});

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

Convert JSON to HTML tooltip content - hide brackets and include <br> tags

I am currently working with a JSON object in my JAVA code. I am trying to display the values of the object using the following HTML and AngularJS syntax: <uib-progress ng-if="month.data" data-toggle="tooltip" title="{{month.dataTest|json}}"> < ...

Obtain Data for Visualizing Graph with JSON within a Database-connected Graph (highchart.js)

In the process of creating a database-driven graph, I am utilizing libraries from Codepen. These libraries include: THIS and Highchart.js The HTML file on display simply showcases the chart, while the main data processing is handled in an index.js file t ...

Is there a way to manipulate a button's toggle state using Javascript as the page loads?

I am in the process of developing a straightforward web application that allows users to customize their settings. On the settings page, there are several toggle buttons that need to have their state changed during the page load to align with the preferenc ...

extracting the HTML content from JavaScript and saving it into a standalone file

update When I click a link, a popup opens and I see all this HTML. The smile method is called when I click the link, and we append HTML in that method so that we can see it when the popup is opened. I moved it to a separate file something.component.html, ...

I'm facing an issue where the ui.router is not functioning properly. I am unsure

I am currently trying to replace ngRoute with ui-router in order to utilize multiple views. Within my template file, I have the following code: <div ui-view></div> In my application file, I have the following configuration: angular.module(&a ...

Is there an easy method for customizing scrollbars?

I'm looking to include an "overflow:scroll" in a navigation div, but the default scrollbar on windows is unattractive. Is there a simple way to customize the scrollbar without having to download extra JavaScript libraries, APIs, and so on? ...

Utilizing AngularJS to create a vertical calendar

Looking to create a vertical navigation displaying the date and day for the current week using angularjs. When clicking on the navigation div, I want an alert with the selected date to appear. I attempted this in Plunker using various templates, but was u ...

How can Vue JS 3 components exchange data between each other?

I am attempting to share data from a variable favorite_count in the Favorites component located in the file Favorites.vue. My goal is to pass this data to the App Component in the App.vue file but I have been unsuccessful so far. I want any changes made to ...

Use $parse to extract the field names that include the dot character

Suppose I have an object with a field that contains a dot character, and I want to parse it using $parse. For instance, the following code currently logs undefined - var getter = $parse('IhaveDot.here'); var context = {"IhaveDot.here": 'Th ...

The latest version of Next.js, Version 12, encounters an issue with theme-ui that results in the error message "code: 'ERR_REQUIRE_ESM'"

Encountering an error while working with Next.js 12 after creating a theme using theme-ui. https://i.stack.imgur.com/BtH7W.png Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: E:\fm-nextjs\node_modules\@mdx-js\react\ind ...

Is there a way to retrieve SQL information through an API and then incorporate that data into react-native-svg charts? I have an API that contains data I would like to retrieve and showcase

I am utilizing an API to retrieve data, which includes the execution of SQL queries. The API is responsible for fetching data and running these queries. I am looking for a way to replace the static data in my charts with dynamic data fetched from the API. ...

Tips for achieving printing with the "Fit sheet on one page" option in JavaScript

Is there a way to print a large table of data with 200 or 300 rows all on one page, similar to the Online MS Excel print option 'Fit Sheet on One Page'? I attempted the code below: var tble = document.createElement("table"); tble.id = "tble"; d ...

Playing sound using jQuery when the body of the page is replaced

I am facing an issue with my website where I have implemented a jQuery full body refresh every 30 seconds. However, I want to add a short sound to play every time the page refreshes. Despite trying various methods, the sound works on my computer browsers ( ...

Creating an executable JAR for your Next.js application: A step-by-step guide

Is there a way to ensure that my Next.js file can run seamlessly on any computer without the need for reinstallation of all modules? In my folder, nextjs-node, I have the following subfolders: components lib public node_modules page style package.json I ...

Is there a way to automatically update a webpage?

When two computers, pc1 and pc2, are on the same page and pc1 changes the status of a field, is there a way to update pc2's aspx page without needing to refresh it? ...

Is it possible to identify if an array is a polygon or multipolygon by examining its GeoJson data?

Recently, I came across an example illustrating a simple polygon. However, I wanted to display countries with complex polygons (multipolygons for some countries). Let me demonstrate the process: Example: "type": "Feature", "properties": { "Na ...

Activate automatic selection when the input field is disabled

How can I enable auto-select for text in an input field even when it is disabled? Currently, the auto select feature doesn't work when the field is disabled. Here is my HTML: <input type="text" class="form-control" ng-model="gameId" select-on-cli ...

Leverage jsencrypt in Ionic 3

Struggling to hash passwords for login on my Ionic 3 app, I attempted using jsencrypt following a tutorial but encountered issues as I couldn't grasp how it works... Here's what I tried : npm install --save jsencrypt import { Component } from ...

What is the way to modify the contents of a div using ajax?

I have blade files in both list and image formats. There are two span buttons here, and I would like to display a list in different formats when each button is clicked. How should I go about writing the code for this? <span id="penpal-image-view" ...

Determine the variance between the final two items in an array composed of objects

I am trying to figure out how to calculate the difference in total income between the last two months based on their IDs. It seems that {income[1]?.total} always gives me a constant value of 900. Any suggestions on how I can accurately calculate the tota ...