Tips for refreshing the chosen item following a redirect to a different page

My current project involves creating an app with the use of ionic item-divider. A key feature is that when a user clicks on the list header, they are redirected to a new view where they can update and delete the selected item. However, I am facing a challenge with updating the selected item as I am unsure how to push both the selected item and its sub-item to the next page for editing and saving. In my controller, I am using the "key" to identify what has been selected, but after that point, I'm struggling to transfer the necessary information to the subsequent page for updates and saves. Below is a link to a Plunker showcasing how my first page appears:

Plunker Link

Main View:

   <ion-list>
   <ion-item ng-model="carBrand" ng-repeat="name in carSelect">       
   <button ng-click="selectItem(name)">{{name.name}}</button>
   <div class="item" ng-repeat="type in name.types">{{type}}</div>
   </ion-item>
   </ion-list>

Answer №1

Common mistakes to avoid: avoid using

$state.go('second.html',{key});

Proper routing is necessary. Avoid explicitly referencing .html files. Update your JavaScript configuration like this:

carService.config(function($stateProvider, $urlRouterProvider) {
  $stateProvider

   .state('first', {
      url: '/first',
      templateUrl: 'templates/first.html',
      controller: 'carBrand'
    })
     .state('second', {
      url: '/second',
      templateUrl: 'templates/second.html',
      controller: 'secondCTRL',
      params: {
          object: null
      }
    });
    $urlRouterProvider.otherwise('/first');
})

Once configured correctly, you can navigate to the second page only. To pass parameters, do it like this:

$state.go('second', {object:key});

If using $rootScope, passing parameters is unnecessary. You can access $rootScope.selectItem in your secondController.

I hope this information proves helpful. 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

Assign a custom value to the ng-options and ensure that the first option is selected by default

Hey there, I'm currently working on the following: $scope.test = [ {"value" : 0, "text" : "00:00"}, {"value" : 900, "text" : "00:15"}, {"value" : 1800, "text" : "00:30"} ]; and in my select element, this is what I hav ...

The respond function does not execute the callback when the path is matched

In an attempt to test a custom AngularJS directive that incorporates an HTML template via a reference, I am encountering an issue with HTTP requests being issued. My goal is to intercept all requests for these templates using httpBackend.whenGET("....").r ...

Encountering a [$injector:modulerr] error while attempting to include modules in ZURB Foundation for Apps

I am currently working on a project that involves specific authentication which is functioning well in Ionic. My task now is to incorporate the same authentication system into the admin panel exclusively for web devices. I have already completed the instal ...

Is there a way to showcase the string message from BadRequest(message) utilizing Ajax?

I am currently working on implementing an API Controller. public ActionResult<Campaigns> AddCampaign([Bind("Name, Venue, AssignedTo, StartedOn, CompletedOn")] Campaigns campaigns) { try { if (ModelState.IsVal ...

In this context, 'number' is typically a data type, but it seems to be functioning as a specific value

Greetings! I'm encountering an issue with this Angular 4 code. Whenever I attempt to type a number, I encounter the following error: 'number' only refers to a type, but is being used as a value here.ts(2693). View image description here ...

Adding javascript code to each page in an asp.net application

I am in the process of implementing GTM on a website with over 400 pages where the GTM script needs to be placed. Is there a way to automatically inject the GTM script on every page right after the body tag? The website utilizes a mix of technologies, in ...

What steps should I take to ensure that jQuery functions remain functional on loaded code?

I have implemented modals on all my pages except for the first one to save time. Here is the script that loads my modals: $(function () { $('#header').load('reusenavbar.php'); $('#loginModal').load('reuseloginmo ...

``motioning a component beneath another component that may be in a state

Having an issue with my CSS. I have some elements generated by JavaScript and when hovering over them, another element is displayed below the others for some reason. Here's the CSS related to this problem: .hiddenTextjob { display:none; ...

jQuery animation for expanding accordion headers

I want to create a cool animation for my accordion headers that mimics a ribbon being dragged onto the wrapper when hovered over, and then dragged out when the hover ends. Everything was working fine in this initial jsFiddle, but as soon as I tried to ani ...

I possess a primary menu with several submenus, yet I am encountering difficulty accessing the submenus. My goal is to efficiently navigate and access the appropriate submenu within the main menu

I am facing an issue with my CSS where the sub menu is currently showing from the left side, but I would like it to slide up and down instead. .outer { width: 100%; text-align: center; background-color: Gray; padding-top: 20px; bord ...

The date of posting will always be '0000-00-00 00:00:00'

I'm experiencing an issue with my JavaScript code for writing reviews. Previously, it worked fine, but now the 'datePosted' column consistently outputs the default '0000-00-00 00:00:00'. writeReview(request, respond) { va ...

Getting started with imports in typescript package

Having trouble with imports in a TypeScript package. I have two classes, A and B, located in the models directory. Currently, I am importing class B into class A like this: import B from "models/B" interface A { b: B } export default A; H ...

Having trouble locating an Ionic module with your Ionic Web Builder?

Currently, I am working on building my Ionic app using their web build system. In my app.component.ts file, I have included the following import statement: import { File } from '@ionic-native/File/ngx'; Although this project compiles successful ...

Guide on displaying two different array elements in a single TR using JSON in AngularJS

I need help with printing two arrays in a single tr. Here is the JSON data: [{"group_name":"Ecofresh","id":"19","userId":"19","device_details":[{"userid":"19","unit_id":"35","unit_name":"Test123","mac_id":"EB9F5E5727D7","m2xa":"95005c74d3cb33ca320e4b92cde ...

Ways to display all current users on a single page within an application

I have come across a project requirement where I need to display the number of active users on each page. I am considering various approaches but unsure of the best practice in these scenarios. Here are a few options I am considering: 1. Using SignalR 2. ...

Create a file object using content with the help of JavaScript

I am working with a file containing specific data const ics = 'BEGIN:VCALENDAR\n' + 'VERSION:2.0\n' + 'CALSCALE:GREGORIAN\n' + 'METHOD:PUBLISH\n' + 'END:VCALENDAR\n'; I am trying t ...

Is there a way to update the state for a specific location on a map?

I have a requirement to update the quantity of a product by using setCount. let [product.quantity, setCount] = useState(product.quantity); Implementing increment and decrement functions for product.quantity const increaseQuantity = () => { setCoun ...

an observable with an empty array inside

I am working with a ko.observable that holds an object containing three arrays structured like this: self.filter({ file: [], site: [], statut: [] })` However, my attempts to empty these arrays have been unsuccessful. I have tried using the code: array = ...

Error message: Unexpected end of input found in HTML, CSS, or JavaScript files

I am currently working on a card game project but I keep encountering an error that says "unexpected end of input". This error is completely new to me, so any assistance or guidance would be greatly appreciated. Additionally, the codepen isn't display ...

Having trouble with reactjs and typescript? Getting the error message that says "Type 'string' is not assignable to type 'never'"?

When trying to setState with componentDidMount after an axios request is completed, you may encounter the error message Type 'string' is not assignable to type 'never'. Below is the code snippet: import * as React from 'react&apos ...