Any advice on how to navigate to a different screen based on the content of a dynamic grid view?

I have a grid view displaying data from my database, with each title representing a separate box. When a title in the grid view is clicked, I want to redirect to a corresponding screen. How can this be achieved?

For example, clicking on "Orders" should redirect to order.html and clicking on "Delivery" should redirect to Delivery.html. Is there a way to achieve this using id or name?

Updated:


.controller('MydashCtrl', function($scope, $state) {

  $scope.Data = [{
    "id": "1",
    "name": "Orders",
    "Image": "http://img.21food.com/20110609/product/1306576307495.jpg"
  },{
    "id": "2",
    "name": "Delivery",
    "Image": "https://www.wildflavors.com/NA-EN/assets/Image/bakery.png"
  },...
  {
    "id": "6",
    "name": "Re-Orders",
    "Image": "http://royalnutrimakmur.com/img/productImg02.jpg"
  }]

   $scope.changestate= function(name) { 

     if(name === "Orders"){
      $state.go('reorder', { details: JSON.stringify(name) });
      }else if(name === "Delivery"){
     $state.go('dashboarddetail', { details: JSON.stringify(name) });
      }
  }
})

My Html code:

Issue: The title content is not showing up on the redirecting screen.

Sample Code for Redirect Screen - Order Title:

Screen HTML code:

<ion-view cache-view="false" title={{singleDetail.name}} hide-nav-bar="false" class="">

Controller code for this html:

.controller('reorderCtrl', function($scope, $state, $stateParams){
  $scope.singleDetail = JSON.parse($stateParams.details);
})

There might be an issue with the home grid view controller affecting the appearance of title content on the redirecting screen.

Answer №1

One way to achieve this is by using a function in ng-click like so:

Simply call the function in your view with the value you want for redirection:

<div ng-click="redirect(Data[$index].name)">Tile</div> //example of one tile

In your Controller, create the redirect function:

    $scope.redirect = function(name) {
      if(name == "Orders"){
      $state.go("app.order"); 
      } else if(name == "Delivery"){
      ... // add your code here
      }
    };

Thank you

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 is the best method for creating a fade effect on a div background?

I am trying to animate a div with the id #test from a 0 opacity background to an opacity of 0.7 using CSS rgba values, but for some reason, the .animate function is not working as expected. Here is my CSS: #test { background-color: rgba(0, 0, 0, 0); ...

Ways to enable scrollbars within a container when the content inside a code tag exceeds the visible area

How do I add scrollbars to a code element if the line of syntax is longer than the view? I've attempted using overflow: scroll, but it's not functioning as expected. As shown in the image, using overflow causes the browser to scroll horizontally ...

Animating the movement of a div

How can I move the div "#menu" to the side when it's clicked on? I've tried the following code: <script> $("#menu").click(function(){ $("this").animate({ marginLeft: "+=250px", }, 1000 ); }); < ...

Is it possible to generate a separate table for each user using PHP?

Embarking on a new adventure, I have chosen to create an online shopping website for a college project. My roadblock comes at the sign-up stage. I envisioned users having separate tables to store products they add to their carts, allowing them to add more ...

Transferring an ES6 class from Node.js to a browser environment

I've been exploring ways to bundle a super basic ES6-style class object for the browser. Here's an example: class Bar { constructor(){ this.title = "Bar"; } } module.exports = Bar; While I can easily utilize this in my node projec ...

Using the datepicker class in an input field causes issues with the functionality of the bootstrap datepicker, specifically the autoclose, endDate, and startDate properties do not function as

I'm facing an issue with my code when I add the datepicker to the input field's class. JS $(document).ready(function () { $("#ActionDateInput").datepicker({ autoclose: true, endDate: new Date() }); }); HTML <input type= ...

Is it possible to utilize personalized functionalities in the main.js file of the Firefox Addon SDK?

Why am I encountering difficulties accessing custom functions with the Firefox Addon SDK? In the code snippet provided below, whenever I click on context menu Sub Item 1, it does not work as intended; It is trying to access the custom function verifyTest( ...

Adding JQuery to a running webpage using the DOM and Opera browser add-ons

I'm currently working on an Opera Extension and I have a question. Is there a way to use the includes folder in order to directly inject jQuery into the live HTML of a webpage? For example, can I change the background color of the DOM to black? If ...

Building a Dynamic Image Carousel with jQuery

Is there a way to create a jQuery Slider similar to the one showcased in this example? I have searched high and low for tutorials or plugins that can help me achieve the same design without any luck. ...

Is it possible to customize the default styling options in Tailwind?

I am currently working on a blog using NextJS, and I have encountered an issue with Tailwind's list style type. It seems that the default styling for list style type is set to list-none, resulting in my <ul> <li> elements not being styled ...

Prevent a submit button from submitting a form using jQuery

I am working on developing a password manager similar to a chrome extension. The goal is to detect the username and password fields when a user tries to log in to a website, such as Facebook, and then prompt the user if they would like to save these creden ...

What is the process for saving appends to variables and converting them to PHP for storage in a database?

<html> <head> <meta charset="utf-8"> <title>Test page for Query YQL</title> <link rel="stylesheet" href="http://hail2u.github.io/css/natural.css"> <!--[if lt IE 9]><script src="http://hail2u.github.io ...

The Ng-View feature is failing to provide the expected output, instead generating an error message stating "RangeError: Maximum call stack size exceeded

Having trouble with Ng-View not displaying the output correctly. When attempting to route from one page to another, I keep encountering the error message: "RangeError: Maximum call stack size exceeded" Please review the following code and provide sugge ...

Strategies for quickly landing in top Google search results

I run a website for classified ads... Whenever users post a new ad, it gets automatically included in our dynamic sitemap (xml). Our sitemaps were submitted to Google via Webmaster Tools about two months ago. While some of the ads are indexed, it is tak ...

How to Use Multiple Arrays in jQuery to Find ChildNodes Based on Class Attribute in HTML?

I manage my weekly schedule manually through a static table. <table> <tr class="live al tv"> <td>October 2</td> <td>12:30 pm</td> <td class="competition"></td> <td>Team A v Team B< ...

Which shortcuts or techniques in jQuery/JavaScript can I implement to simplify this code further?

I've written a script to handle responsive design for smaller devices and display a toggle menu instead of a full-width menu. The current script works, but I find it messy. How can I make this code more minimalistic and efficient? Is it good practice ...

Guide on activating javascript code for form validation using php

How can I activate JavaScript code for form validation? I am currently implementing form validation on a combined login/register form where the login form is initially displayed and the register form becomes visible when a user clicks a button, triggering ...

Arrangement of images in an array

Here's the scenario I'm facing. https://i.stack.imgur.com/FbAfw.jpg So, I have an array of images that I want to use to create a gallery with a specific layout. I've tried using grid and playing around with :nth-child(even) and :nth-child( ...

Steps for implementing overflow scroll on a div with an unspecified height

The layout I'm working with looks like this: .page { width: 360px; height: 704px; border: 1px solid red; } header { height: 10%; width: 100%; display: flex; align-items: center; justify-content: center; background-color: lightblue; } ...

Why is it necessary to use 'this.' to reference a function inside a Component in React?

class First extends React.Component{ handleClick(){ alert('handle click'); } render(){ return <div> <button onClick={this.handleClick}>click</button> </div>; } } Explo ...