parent triggers resolution when sending a signal to child

My routes using ui-router are structured like this:

    $stateProvider
        .state('studies', {
            url: '/studies?all&field&term&page&sort&sort_dir',
            templateUrl: 'scripts/studies/studies.template.html',
            controller: 'StudiesController',
            onExit: function exitStudies(filterQuery) {
                filterQuery.emptyQuery();
            },
            menuElement: 'studies',
            resolve: {
                attributes: function (manageAttributes, attributeDefinition, $q) {
                    console.log('resolve');
                    var promises = {
                        columnDefinitions: attributeDefinition.fillColumnsDefinitions(),
                        userColumns: manageAttributes.queryAttributes()
                    }
                    return $q.all(promises)
                        .then(function (response) {
                        var attributes = _.map(response.userColumns, function (object) {
                            return _.find(manageAttributes.getAllAttributes(), function (attribute) {
                                return attribute.name === object.name;
                            });
                        });
                        manageAttributes.setAttributes(attributes);
                    });
                }
            }
        });
        ['favorites-list', 'favorites-filter', 'default-filter'].forEach(function(directive) {
            $stateProvider.state('studies.' + directive, {
                template: '<' + directive + '></' + directive + '>'
            });
        });

When I navigate to a child route named "favorites," the resolve is triggered even though there is no URL specified for the child route. I intentionally did not want the URL to change when navigating to the child route.

Upon adding the following code:

.run(function($rootScope, $state) {
    $rootScope.$on('$stateChangeSuccess', function(event, toState, toParams, fromState, fromParams) {
        console.log('state: ' + fromState.name + ' -> ' + toState.name);
    });
});

I noticed the following messages in the console:

resolve
state:  -> studies
resolve
state: studies -> studies.favorites-list

This raises the question: why is the resolve being triggered when navigating to a child route?

Answer №1

The traits of their parents are passed down to children in the world of ui-router. This is a natural process that is meant to happen. If you wish to change this behavior, you may reorganize your code so that it does not function as a child state. Alternatively, you could try overriding the resolve within the child state to return a null value (although I have not personally tested this method).

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

How to implement the Ionic ToastController without being confined to a Vue instance

I am currently facing a challenge while trying to utilize the ToastController of Ionic outside a vue instance. I have created a separate actions file which will be loaded within the vue instance, handling a request. Within this request, certain validations ...

Unable to deploy a node.js package via a jenkins job

I'm looking to set up a Jenkins job that will publish a package to npmjs.com. The source code for the package is located in a GitHub repository. While I am able to successfully publish the package from my personal computer by running 'npm publis ...

Assistance needed with selecting elements using jQuery

After some practice with jQuery, I managed to select this specific portion from a lengthy HTML file. My goal is to extract the values of subject, body, and date_or_offset (these are name attributes). How can I achieve this? Let's assume this snippet i ...

How to unbind an AngularJS directive without causing scope destruction

Is there a way to completely unbind all the values from a directive template without destroying its scope? I typically use scope.$destroy for this task, but in this specific case I can't destroy the scope because it inherits from the parent and I sti ...

Success is returned as AJAX error

My AJAX call is returning an error as Success instead of a JSON error from ASP.NET MVC. Can someone please advise on how I can resolve this issue? Thank you. [HttpPost] public JsonResult Register(int EventID) { try { ...

What is the best way to merge two fetch requests in order to gather the required data?

If I want to create a website with details about movies, one crucial aspect is getting information on genres. However, there's a challenge in the main data request where genres are represented by IDs. I need to execute another query that includes thes ...

Angular: issue with accessing deferred variable within then-method

When working with my Angular.JS code, I encountered an issue while calling the Yahoo YQL API using GET/JSONP. Although I receive a response, there are two specific problems that arise. Instead of triggering the success method, it calls the error method. ...

Call a PHP function within a functions file using a JavaScript function

Seeking a way to navigate between PHP and JavaScript worlds with confidence. There's a collection of PHP functions stored neatly in custom_functions.php waiting to be called from JavaScript. As I delve into the realm of JavaScript and jQuery, my fam ...

Is it possible to observe a collection of variables that are not within the current scope, but are still being utilized in Angular?

Consider the following scenario with data coming from a service: myService.var1 myService.var2 myService.var3 Typically, you would need to monitor each variable individually like this: $scope.$watch(function(){ return myService.var1 }, fun ...

Using JavaScript to implement word filtering in MongoDB

I'm currently in the process of creating a chatbot designed to filter questions, and I'm seeking guidance on how to refine the search in my MongoDb based on user input. At the moment, I have the following code: I aim to retrieve all the results ...

utilize Angular's interface-calling capabilities

In the backend, I have an interface structured like this: export interface DailyGoal extends Base { date: Date; percentage: number; } Now, I am attempting to reference that in my component.ts file import { DailyGoal } from '../../interfaces' ...

What steps can I take to resolve the issue with the cdk module?

click here for image This persistent error keeps appearing whenever I try to resize the window. I was hoping that when I decrease the page size, the search bar would transform into an icon with a dropdown search function. Despite my attempts to modify the ...

Updating Angular model remotely without relying solely on the controller

I am struggling to call the addRectangleMethod method from my Javascript code in order to retrieve server-side information into the Angular datamodel. However, I keep encountering an error stating that the method I'm trying to call is undefined. It&ap ...

Establishing a bidirectional binding directive attribute within an AngularJS HTML structure

I'm new to AngularJs and I've encountered a problem that might be due to my lack of understanding about directives, controllers, and isolated scopes. I'm trying to figure out how to set a directive attribute to true/false in the html and kee ...

Issue with active class in Bootstrap navigation tabs

Check out the following HTML snippet: <div class="process"> <h2 style="text-transform: uppercase;">The Application Process</h2> <br><br> <div class="row"> <div class="col-md-3" align="left"& ...

Encountered issue while converting half of the string array to JSON using JavaScript

I encountered an issue with the code below while trying to convert an array into JSON. Here is my code: <html> <head> </head> <body style="text-align:center;" id="body"> <p id="GFG_UP1" style="font-size: 16px;"> </p ...

Struggling to sort data within ng-repeat using tabs?

Here is a JSON object I am working with: $scope.projects = [ { "_id": "58ab1cb6edf5430e9014e2bc", "name": "Project 1", "issues": [ { "status": 0, "name": "Hart Cummings" }, { "status": 1, ...

Maintain user authentication in Firebase as long as the localStorage object remains active

I am currently working on an app using Ionic, Angular2, and Firebase. My approach involves saving the auth.currentUser information in the localStorage when a user logs in or registers. However, I recently discovered that having the user variable set in th ...

What is the best way to navigate from a button in NextJS to another page that I have built within the same application?

As I work on developing a website for a pet rescue charity using Next.js, I am facing an issue with getting my button or link to function correctly. Every time I try to navigate to another page within my Next.js app, I encounter a 404 error stating "This p ...

Local storage has the limitation of being able to store only a single object at a time, rather

This code is designed to store product details in a local storage variable whenever a user visits a product page, with the intention of remembering the last visited products. However, the variable currently only retains one product at a time instead of add ...