Transfer an object to $state.go

I'm having trouble solving this issue. Here's the state I am working with:

    var myState:ng.ui.IState = <ng.ui.IState> {
        url: '/new/{order.orderNumber}',
        controller: 'OrderController',
        controllerAs: 'vm',
        templateUrl: '/order.tpl.html',
        resolve: {
            order: ['OrderService', '$stateParams', '$q', duplicateOrder]
        }
    };

When I try to go to this state using:

this.state.go("myState", {"order": order});

The method duplicateOrder within the resolveFunction cannot find the order Object, as $stateParams is empty.

If I use a String instead of an object, everything works fine. I am currently using UI-Router v0.2.18, but I have read that objects were possible since v0.2.13.

Answer №1

Make sure to include params in your state object as shown below:

var myState:ng.ui.IState = <ng.ui.IState> {
        url: '/new/{order.orderNumber}',
        controller: 'OrderController',
        controllerAs: 'vm',
        templateUrl: '/order.tpl.html',
        params:{order:null},
        resolve: {
            order: ['OrderService', '$stateParams', '$q', duplicateOrder]
        }
    };

This code snippet initializes the $stateParams.order with null. When you use

$state.go("myState",{order:order})
, it will update the value with the provided data.

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

Leverage es6 classes along with mongoose in typescript to utilize loadClass functionality

I've been struggling with a problem and despite my exhaustive search on Google, I still haven't found a solution. My issue revolves around incorporating es6 classes with mongoose using the schema.loadClass(class) method. Unfortunately, when worki ...

A guide on leveraging console.log in Next.js

I'm having trouble displaying the output of an API call using console.log. The issue is that nothing appears in the console (both in the browser and Visual Studio Code). The only console.log that seems to work is within the RouteStatus function, but i ...

Using Unique Typeface in Ionic Framework 3

I am currently utilizing Ionic3: Your device information: Cordova CLI: 6.4.0 Ionic Framework Version: 3.0.1 Ionic CLI Version: 2.1.18 Ionic App Lib Version: 2.1.9 Ionic App Scripts Version: 1.3.0 ios-deploy version: Not installed ios-sim version: Not in ...

Repurposing React key usage

section, I am curious to know if it is standard practice to reuse a React key from one component to another. For instance, in the Row component, the key obtained from the Column component is reused for mapping the children of Row. const Table = props =& ...

I'm having trouble modifying the backdrop to 'true' or removing it after setting it to 'static' in Bootstrap. Can anyone help me troubleshoot this issue?

I have been encountering an issue with changing the backdrop setting from 'static' to 'true' in Bootstrap modal. Here is the code I am using: $('#modal').modal({backdrop: 'static', keyboard: false, show: true}); ...

Contrast between categories and namespaces in TypeScript

Can you clarify the distinction between classes and namespaces in TypeScript? I understand that creating a class with static methods allows for accessing them without instantiating the class, which seems to align with the purpose of namespaces. I am aware ...

What other local variables can be passed into a controller in addition to the $scope variable?

Angular allows for dependencies to be injected, but it's important to note that injecting $scope into a directive doesn't work. Is there a definitive list available outlining what can be injected into controllers and what cannot? What about direc ...

Tips for fixing type declaration in a generic interface

Here is a simple function that constructs a tree structure. interface CommonItem { id: string parent: string | null } interface CommonTreeItem { children: CommonTreeItem[] } export const generateTree = <Item extends CommonItem, TreeItem extends ...

Obtain a filtering dropdown list directly from the database within Ag-grid

Currently in my interface, I am attempting to implement a filter for the FOLDER column. This filter is supposed to retrieve data from the database and present it in a dropdown checkbox within that column. The filtering should be based on the selected data. ...

What is the reason behind the narrowing of the type by indexing into a mapped type?

This question is inspired by an amazing answer found here: My curiosity lies in why the indexing works in the mapped type trick. Let's illustrate with an example: type MyData = { a: { alpha: string; }; b: { beta: number; } } type ...

Invoke a parent method from a nested child component in Vue

After setting up a project with vue-cli using the webpack template, I decided to incorporate a reusable bootstrap modal dialog in the App component. To achieve this, I created a method called showMessage in the App component that handles displaying the mod ...

Create a random number within a specified range using a different number in JavaScript

I am looking for a unique function that can generate a number within a specified range, based on a provided number. An example of the function would be: function getNumber(minimum, maximum, number) { ... } If I were to input: getNumber(0, 3, 12837623); ...

Increase the current time by 50 minutes

I have a dropdown menu with various time options like this: <select name="" id="delyvery-hour"> <option value="18:00">18:00</option> <option value="18:05">18:05</option> <option ...

Is there a way to retrieve keys of the object from this combination type?

Can someone please help me understand how to retrieve keys from this union type? The Value is currently being assigned as a never type. I would like the Value to be either sno, key, or id type Key = { sno: number } | { key: number } | { id: number }; typ ...

The initial request does not include the cookie

My server.js file in the express application has the following code: var express = require('express'); var fallback = require('express-history-api-fallback'); var compress = require('compression'); var favicon = require(&apos ...

What is the best method for accessing the service response data when I am sending back an array of custom map with a promise as an object?

Sharing my code snippet below: function createObject(title, array){ this.title = title; this.array = array; } //$scope.objects is an array of objects function mapPromise(title, promise){ this.title= title; this.promise = promise; }; var fet ...

Exploring the method of creating multiple nested states within various parent components while utilizing identical templates

I have developed a mobile site for purchasing, renewing, and transferring domains. The app consists of 4 templates that work together in a functional chain. Buy : Search -> (login if necessary?) -> Pay -> Confirmation Renew : Choose -& ...

Steps to invoke a function in a PHP file from an external JavaScript file

Can anyone assist me with calling the function below in my PHP file? function update_hidden_input(saved_tokens, hidden_input) { var token_values = $.map(saved_tokens, function (el) { //alert(el[settings.tokenValue]); return el[ ...

Updating the parameter names in an AJAX request

Can the data parameters sent with AJAX be dynamically changed to a new name? For instance: let NewParamName = `Post_${incremented_value}`; $.post("index.php" { NewParamName : "someValue" }); Even after sending the request, the name in the parameters rem ...

Tips for implementing an automated date picker in Selenium using Node.js

I attempted to automate a date picker like the one shown in this screenshot: https://i.sstatic.net/GtJ22.png Below is the code I used to automate it using Selenium with NodeJS: const { By, Key, Builder, WebElement, Alert } = require('selenium-webd ...