Navigate to a new tab with a parameter in AngularJS

Is there a way to open a new tab using state.go with parameters?

This is the state configuration:

 .state("view", {
    url: "/view",
    templateUrl: 'app/components/view/view.html',
    controller: 'viewController',
    params: {
      data: ''
    }
  })

In the controller:

var url = $state.href('view', {data: JSON.stringify($scope.data)});

    window.open(url,'_blank');

Although the above code successfully redirects to a new tab, I am unable to retrieve the passed parameter values in the viewcontroller.

Answer №1

To properly utilize $stateParams in your controller, make sure to include it as a dependency like shown below:

.state("details", {
   url: "/details/:info",
   templateUrl: 'app/components/details/details.html',
   controller: 'detailsController'
})

.controller('detailsController', ['$stateParams', function($stateParams) {
    $scope.info = $stateParams.data; // This line retrieves parameter values
})

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

What advantages does Redux offer?

I've been considering diving into the world of ReactJS lately and I could really use some guidance on when to incorporate Redux. The concept seems a bit complex to me, especially coming from an Angular2+ background. Although I've come across sev ...

Exploring the use of Angular with tables: applying classes dynamically using ngClass and repeating items using

My table is generated from a Web Service JSON, each row has a button to mark it for deletion. When you click the button, a JS alert displays the ID of the row element, and I also need to add the 'danger' bootstrap class to the row. Now, I can cap ...

"Sweet syntax" for assigning object property if the value is true

In the project I'm working on, I find myself dealing with a lot of parsing and validating tasks. This often results in 5-10+ lines of code like if(value) object.value = value. I considered using object.value = value || (your favorite falsy value) app ...

Unlocking the potential of AngularJS: A guide to using factories effectively across

I created a factory function to provide specific options for all name fields and I am looking to globally utilize or invoke that factory in the application. How can I achieve this global usage? Below is the code snippet I have written: checks.factory(&ap ...

What is the best way to integrate JavaScript into an Express Handlebars template using partials?

In my current project, I have utilized the following handlebars template (located under views/layouts/main.handlebars): <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>{{title}}</title> ...

Refresh TR when clicked

I have a HTML table that lists items from SQL, using <tr> and <td>. The table is housed within a div that is refreshed every 30 seconds with jQuery AJAX (hence the unique id on the div). Here is the HTML code: function auto_load() { $.aj ...

Trouble with CSS animation when incorporating JavaScript variables from a PHP array

Whenever I use a script to fetch an array of objects from PHP... I successfully display the results on my website by outputting them into Divs. The challenge arises when I introduce CSS animations. The animation only triggers if the variable length excee ...

Guide on retrieving a nested JSON array to extract a comprehensive list of values from every parameter within every object

A JSON file with various data points is available: { "success": true, "dataPoints": [{ "count_id": 4, "avg_temperature": 2817, "startTime": "00:00:00", "endTime": "00:19:59.999" }, ... I am trying to extract all the values of & ...

How do I use React and Material-UI to efficiently display multiple tables from a complex JSON object containing multiple arrays of data?

Trying to come up with an innovative approach to generate a unique dynamic table component that can create individual tables based on the number of arrays in a dictionary object (essentially iterating through each array and generating a table). For my sce ...

Typescript struggling to load the hefty json file

Currently, I am attempting to load a JSON file within my program. Here's the code snippet that I have used: seed.d.ts: declare module "*.json" { const value: any; export default value; } dataset.ts: import * as data from "./my.json" ...

Explanation of JavaScript code snippet

fnTest = /abc/.test(function () { abc; }) ? /\bchild\b/ : /.*/; I am struggling to comprehend the functionality of this particular javascript snippet. Would someone be able to elaborate on the logic behind this code fragment? ...

A guide to setting up a unit test for an Angular JS controller that utilizes an ajax service

I've been attempting to write unit tests for the code below, but I'm struggling to make it work. Service Code: angular.module('ActivityApp').service('PersonService', [ '$http', function ($http) { v ...

Generating a dynamic array of ngGrids following the completion of page loading

Currently, I am facing a challenge with my Angular application. I import a spreadsheet into the app, perform some JavaScript operations, and aim to display a variable number of tabs, each containing an ngGrid based on the data from the spreadsheet. This re ...

What is the reason behind the controller being unable to locate an Angular model when it contains dots in its name?

I am completely new to Angular and struggling to comprehend this code snippet. app.controller('FileConfigController-detail', function($scope, $http, $stateParams, FileConfigDetailsService) { $scope.detail.inptITResourceID = "test me" ...

TypeError: "Table" has not been declared

This is my first experience with the script editor. I have been given the task of creating a pivot table for Google Sheets using a script. // This script creates a pivot table in Google Sheets function createPivotTable() { var ss = SpreadsheetApp.getAc ...

Set the array back to its initial value of 1 using jQuery and

After making substantial edits to this question, I find myself in need of a reset button for the code. The current item needs to be reset back to 1 so that I can use it again, but the issue lies in the fact that only the current item is reset while the hig ...

verifying an email address through firebase using the verifyPasswordResetCode method

Currently in the process of setting up firebase authentication. Instead of relying on firebase's default pages for recovery password and email verification, I want to handle these processes directly on my website. To customize the recovery steps: U ...

Synchronizing the DOM with the Database in a React Component/View: A Step-by-Step

I recently developed a list component in React, but I'm facing two significant challenges. Although the item gets removed from the database, the change is only visible after refreshing the page. You might have noticed that the list number or ID colu ...

Displaying a component following data retrieval in Vue.js

I am currently working on consuming an API using axios. Here is the code I have so far: <select> <option v-for="value in values"> value.name </option> </select> // js data(){ values: [], }, create ...

I am looking to create a straightforward AngularJS unit test for a controller that successfully passes the defined criteria

Testing the definition of the controller. 'use strict'; mainApp.controller('HeaderCtrl', function ($scope, sessionSrvc, eventSrvc, $state) { // Code for handling user session and visibility of sign in/out buttons /** * ...