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

Check the output of the ChildProcess after executing a shell command

I am currently running the ChildProcess function within a Nextjs API route and I am struggling to retrieve the value from it. const output = exec( "curl -s -v https://test.com/index.php", (err, stdout, stderr) => { if (err) { ...

What causes axios to return a z_buf_error?

I've encountered an issue with axios returning an error cause: Error: unexpected end of file at BrotliDecoder.zlibOnError [as onerror] (node:zlib:189:17) { errno: -5, code: 'Z_BUF_ERROR' I'm puzzled as to why this functio ...

Exploring the JSON data received from PHP script via jQuery AJAX

In my program, I have created a web page with 5 radio buttons for selection. The goal is to change the picture displayed below the buttons each time a different button is chosen. However, I am encountering an issue during the JSON decoding phase after rec ...

Can you explain the distinctions among <Div>, <StyledDiv>, and <Box sx={...}> within the MUI framework?

When exploring the MUI documentation, I came across a table of benchmark cases that can be found here. However, the differences between the various cases are not clear to me. Can someone please explain these variances with real examples for the following: ...

Steps for linking a keypress to trigger a specific action

I need help creating a script that will redirect to a URL when a button is clicked. Below is the code I have developed. HTML : <a id="#next" href="example.com">↵</a> <a id="#previous" href="example.com">↳</a> JS : $(document ...

Steps for closing the menu by clicking on the link

My issue with the menu on the landing page is that it only closes when clicking the cross button. I want it to close when any link from the menu is clicked. I attempted to add code using querySelector, but it only worked for the home link and not the other ...

Using two controllers for one template in AngularJS state provider routing: a guide

Exploring the use of state provider for routing, I am faced with a challenge. How can I incorporate two controllers for a single template? What would be the correct syntax to achieve this? I have attempted the following approach: $stateProvider.state("ho ...

Halting Execution After Placing an Object in Three.js Scene with Javascript

It seems like a simple task, but I've been struggling with it for days. How can I add objects to a scene with a pause between each addition? Inside a loop{ I call the make_obj function() then I call the wait function() } The issue is that the pr ...

Using JavaScript's if-else statements is akin to a checkbox that is always in its

When working with checkboxes, I can retrieve the state (checked or unchecked) in the browser developer console using $("#blackbox").prop('checked')or $('#blackbox').is(':checked'). I have tried both methods. For example, if I ...

struggling to determine the connection status between tables (Many-to-many or one-to-one)

Seeking assistance: I am working with two tables (member, event) where each member attends multiple events and each event has multiple attendees. Do these relationships represent a many-to-many or one-to-one relationship? ...

JavaScript Alternatives for jQuery Functions

Currently in the process of eliminating the jQuery dependency from my AngularJS project, I encountered the following code as part of a spec within my codebase: beforeEach(inject(function($rootScope, _$compile_) { scope = $rootScope; $compile = _$c ...

Utilizing Chart.js for generating a sleek and informative line graph

After executing a MySQL query, I obtained two tables named table1 (pl_pl) and table2 (act_act) with the following data: table1: label act_hrs Jan-19 7 Feb-20 8 Mar-20 9 table2: label pl_hrs Mar-20 45 Apr-20 53 I am looking to create a line cha ...

Tips on embedding a textField into a designated row within a table by clicking a button with the help of reactjs and material ui

I need assistance adding multiple text fields to a specific row within a table when a designated row's "add" button is clicked. Currently, I am able to add a text field when the button is clicked, but it adds the text field to every row in the table. ...

Can PHP be used to create a new page whenever Javascript history.go(-1) is triggered?

A PHP file (a.php) is currently sending the following headers: <?php header('Cache-Control: no-cache, no-store, max-age=0, must-revalidate'); header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); header('Pragma: no-cache'); ? ...

Issue with model not displaying after material added in OBLLoader + MTLLoader

After loading a material using MTLLoader and applying it to my model loaded with OBJLoader, the model itself mysteriously disappears. MTLLoader.setPath( 'models/' ); var url = "model.mtl"; MTLLoader.load( url, function( materials ) { materi ...

Testing URL Parameters in JEST with an API

Seeking integration tests using Jest for an API endpoint. Here's the specific endpoint: http://localhost/universities/ucla/class/2013/studentalis/johndoe. When tested with a put request, it returns 201 on Postman. However, the testing encountered a t ...

Picking out specific elements from a component that is rendered multiple times in a React application

One of the challenges I face involves a component called card, which is rendered multiple times with different data. Here's how it looks: { this.state.response.reminders.map((item,i=0) =>{ return <Card key={i++} reminder={item} deleteRem={th ...

Create a series of canvas lines connecting all divs that share a common class identifier

Currently, I am in the process of creating a document that will establish a tree-type graph based on user input. My goal is to link styled divs with canvas lines to show their connection to the parent div. I have been utilizing .getBoundingClientRect() to ...

Tips for utilizing navigator.getDisplayMedia with automatic screen selection:

navigator.mediaDevices.getDisplayMedia({ audio: false, video: true }).then(gotMedia).catch(function(e) { console.log('getDisplayMedia() error: ', e); }); Triggering the above code will result in a popup like this. There is anoth ...

Using the Parallax Effect in React

I'm currently working on implementing a parallax effect in React and I've encountered an error that's giving me trouble: Below is the snippet of JavaScript code I have for the parallax effect: export const parallax = document.getElementsBy ...