A fresh controller instance was instantiated upon calling $state.go() in angular-ui-router

I'm struggling to grasp the concept of routing with angular-ui-router and states.

My application is built on ionic (v1), angular, and esri jsapi. I am utilizing the ionic side menu and angular-ui-router. Upon loading my site, the map view is displayed. When navigating to a station using the side menu, then viewing the station details, and clicking the map button to zoom in on the location, I use $state.go() to return to the map view, and notice that the view/controller is re-initialized. This can be observed by checking the console and seeing "CREATE MAP" being displayed again after the initial loading of the map view.

The state configurations are as follows:

        .state('app.map', {
            url: '/map',
            cache: true,
            reload: false,
            params: {
                attributes: null
            },
            views: {
                'menuContent': {
                    templateUrl: 'templates/map.html',
                    controller: 'MapController'
                }
            }
        })
        .state('app.detail', {
            url: '/detail',
            cache: false,
            params: {
                properties: null
            },
            views: {
                'menuContent': {
                    templateUrl: 'templates/detail.html',
                    controller: 'DetailController'
                }
            }
        })

I am looking for a way to prevent the map view/controller from being re-instantiated when transitioning from the detail view back to the map view. I expect the button click from the detail page to take me back to the original map view state, but it seems to be attempting to create another instance of the map view. However, if I click on the side menu button for the map, it does not re-initialize and I see the original map view.

View my site here:

EV Charge Stations

Answer №1

Check out these discussion threads for potential solutions: https://github.com/angular-ui/ui-router/issues/1758, https://github.com/angular-ui/ui-router/issues/64

If everything is functioning properly when using ng-href in the side menu map option, consider switching from ng-click to ui-href and invoking a function that returns the state name. Here's an example:

    <ion-item ng-repeat="feature in features | filter: {attributes: {Property: search.input}} as filteredCount" 
class="item item-icon-left item-icon-right"
 ui-sref={{onListItemClick({&quot;Station_Id&quot;:487,&quot;Property&quot;:&quot;Neal Blaisdell Center Parking Structure&quot;,&quot;Street_Address&quot;:&quot;777 Ward Avenue&quot;,&quot;City&quot;:&quot;Honolulu&quot;,&quot;Zip_Code&quot;:96814,&quot;Island&quot;:&quot;Oahu&quot;,&quot;In_Use&quot;:&quot;No&quot;,&quot;Charger_Fee_Type&quot;:&quot;Free&quot;,&quot;Charger_Notes&quot;:&quot;Enter S. King Street/Victoria street.  Follow blue signs to Charger.&quot;,&quot;Hours_of_Operation&quot;:&quot;6:00am-12:00am&quot;,&quot;Charger_Count&quot;:1,&quot;Charger_Port&quot;:1,&quot;Charger_Level&quot;:2,&quot;Charger_Fee&quot;:&quot;Free&quot;,&quot;Parking_Fee&quot;:&quot;Free for EV Drivers&quot;,&quot;Network&quot;:&quot;ChargePoint&quot;,&quot;Notes&quot;:&quot;Activate charger with ChargePoint Network card or call the number listed on the front of the charger for access. &quot;,&quot;Latitude&quot;:21.299434,&quot;Longitude&quot;:-157.850378,&quot;Location&quot;:&quot;(21.299434, -157.850378)&quot;,&quot;Other1&quot;:null,&quot;Other2&quot;:null,&quot;Other3&quot;:null,&quot;Other4&quot;:null,&quot;Other5&quot;:null,&quot;Other6&quot;:null,&quot;Other7&quot;:null,&quot;Other8&quot;:null,&quot;Other9&quot;:null,&quot;Other10&quot;:null,&quot;FID&quot;:3,&quot;CreationDate&quot;:1484871379520,&quot;Creator&quot;:&quot;dpascual_HEC&quot;,&quot;EditDate&quot;:1484871379520,&quot;Editor&quot;:&quot;dpascual_HEC&quot;,&quot;Hawaiian_Station&quot;:null,&quot;OwnedBy&quot;:null,&quot;ChargingStandards&quot;:null,&quot;Servicing&quot;:null,&quot;ServiceNotes&quot;:null}) }}>

                </ion-item>

Controller.js

$scope.onListItemClick = function (attributes) {
            var data = {
                properties: attributes
            };
            return "app.detail({attributes:"+data+"})" ;
        }

Hopefully this solution resolves your issue.

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

Integration of AngularJS with PHP for Seamless User Authentication

As a newcomer to angularjs, I find the Login Process a bit confusing. Every time I log in, I'm automatically redirected to a specific page that is already set in the code. I just want a simple check to see if the user is logged in. If they are, then ...

Storing various values in the database using CakePHP 3

While working on receiving data, I encountered an issue where the saved time in the database is different from what was input. For example, when I send 8:00 pm, it gets saved as 12:00 am due to a +4 hour difference. When I receive data from a form and che ...

The perfect combination: Symfony2 and AngularJS working together

Currently, I have been working on a web app that utilizes Symfony2 and recently integrated AngularJS. Within this app, there is an input field where users can filter products by name. The issue arises when it comes to querying the database in PHP and passi ...

Is it advisable to load 10,000 rows into memory within my Angular application?

Currently, I am in the process of creating a customer management tool using Angular.js that will allow me to directly load 10,000 customers into the $scope. This enables me to efficiently search for specific data and manipulate it without the need for serv ...

Tips for structuring a SQL query result in an AngularJS application

Forgive me if this code is not up to par with the best standards, as I am still relatively new to angular.js. The issue I am facing is that when the data is returned from my query, it appears as a block of text. Despite using echo statements in search.php ...

Strategies for optimizing polling of mySQL database using $http.get

** ANGULAR 1.X ** Hey there! I'm currently seeking assistance in making this $http.get function asynchronous. Currently, my workaround involves using a setInterval on the displayData scope. However, this solution is not efficient as it consumes a lot ...

troubleshooting problems with AJAX calls and routing in Angular

I am a beginner with Angular and I recently completed a tutorial on Single Page Application development using templates imported from PHP files, along with Resource and Route modules. Below is the JavaScript code from my project: (function(){ var app ...

AngularJS $http.get request failing to retrieve data

I've been delving into AngularJS lately, but I'm having trouble displaying the data from my MySQL database on the view. Here's the code snippets I'm working with: todoController.js angular .module('todoApp') .control ...

No data found in php://input when accessing Azure

Having an issue with posting a complex JSON object to my Azure IIS server running PHP 5.4 using AngularJS: var request = $http({ method: "post", url: "/php/mail.php", data: $scope.contactForm, headers: { 'Content-Type': & ...

Incorporating dynamic images into Laravel using Angular

I am currently trying to dynamically input the src value of an image using Angular. Below is the code I have written : HTML : <div ng-app="myApp" ng-controller="MyCtrl"> <img src="{{asset('assets/img/'.'/'. @{{ item.name ...

Having trouble parsing JSON data from $_POST while utilizing AngularJS

While working in Angular, I encountered the following scenario: var data = {}; data['name'] = "test"; data['class'] = "testClass"; $http.post('http://testURL',data,function(data){ console.log(data); }); Upon inspecting the ...

Unable to process login information with form method post on basic login page

Hi, I've been struggling with a simple login page issue. It works fine with Bootstrap, but I want to switch to Angular Material Design. I've been searching for the problem for about 3-4 hours and can't find anything. I suspect that the form ...

Struggling to make $http post requests to PHP using Angular

I am experiencing difficulties in transferring data to my PHP file after decoding Json, resulting in an error. I need assistance in identifying where I have made a mistake. app.js $scope.formPost = function(){ $http.post('sendmail.php' ...

What methods can be used to effectively store session data in an Angular application when the page is refreshed?

Joomla serves as the backend of our application. Upon a successful login via an ajax call, I am able to obtain the Session ID. What is the most effective way to store this information within the Angular App? Which method is recommended (e.g. cookies or ...

Invalid preflight response (redirect) error

I am a beginner in utilizing Laravel and Lumen frameworks for my projects. Currently, I am working on my first project using Lumen and attempting to create an API call from Angular. Below is the Angular code snippet: app.controller('ListCtrl', ...

Identifying the user's location within the application and dynamically loading various Angular scripts

Currently, I am working on a large-scale web application using Laravel and Angular. In this project, I have integrated various angular modules that come with their own controllers, directives, and views. One challenge I am facing is the need to load diffe ...

Encountering an issue with the Ionic Serve Command

Currently, I am working on creating a mobile app with the Ionic framework. After running the command ionic server, I encountered this error: /deps/uv/src/unix/stream.c:494: uv__server_io: Assertion `events == 1' failed Any suggestions or assistanc ...

Dealing with incoming data in a yii2 RESTful service

When sending an array using $http post, I follow this approach: var results = services.transaction('orderdetails/insert', {customer_id: $scope.order.customer_id, data: $scope.orderDetail}); The variable $scope.orderdetail ...

How to address the error "Unable to convert object of class stdClass to string" in Codeigniter and Ionic?

I've encountered an issue with my code for fetching data from the web to my Ionic app. I keep receiving the error message "Object of class stdClass could not be converted to string." Can anyone provide guidance on how to resolve this? https://i.stack ...

Submitting a File Using AngularJS and PHP

Attempting to upload a file utilizing Angular JS and PHP through a formdata object. Wanting to utilize key1 (data) value as JSON to transmit filename and user info to the php script Opting for key2 (uploadFile), value being the file currently being uploa ...