Upon refreshing, my view lost its configuration

As a newcomer to AngularJS, I am encountering numerous challenges in solving some minor issues. One specific problem I am facing is that when my view refreshes, the configuration settings are lost. To elaborate further, I have a tab at the top of the view with labels and textboxes below it. However, when my code saves certain configurations from SQLite, Ionic seems to forget the tab and the objects underneath become hidden by the tab.

Below is the code used to call SQLite:

Controller:

.controller('ClienteDetalheCtrl', ['clientesFactory', '$scope', '$state', '$window', '$rootScope', function (clientesFactory, $scope, $state, $window, $rootScope) {
  buscaEquipamento();
  alteraData();

  function buscaEquipamento() {
      clientesFactory.selectTodos('equipamento');
      $scope.selecionaInstalacao = clienteselec;
  }

}

SQLite call:

 var db = null;
 var clienteselec = [];
 angular.module('sqlite', ['ionic', 'ngCordova'])

.run(function ($ionicPlatform, $cordovaSQLite) {
   $ionicPlatform.ready(function () {
       db = $cordovaSQLite.openDB({ name: "rollers.db", location: 1 });

       $cordovaSQLite.execute(db, "CREATE TABLE IF NOT EXISTS clientes (id integer primary key, nome varchar(40), TC int)");
       $cordovaSQLite.execute(db, "CREATE TABLE IF NOT EXISTS instalacao (id integer primary key, idCliente int, dataInst datetime)");
       $cordovaSQLite.execute(db, "CREATE TABLE IF NOT EXISTS manutencao (id integer primary key, idCliente int, idInstalacao int, dataManut datetime)");
       $cordovaSQLite.execute(db, "CREATE TABLE IF NOT EXISTS equipamento (id integer primary key, idCliente int, idInstalacao int, idManutencao int, TC int, posicao varcar(1), Rolo varchar(40), dataEquip datetime)");
    });
})

.factory('clientesFactory', function ($ionicPlatform, $cordovaSQLite) {

        selectTodos: function (tab) {
            var query = "SELECT * FROM " + tab;

            clienteselec = [];
            $cordovaSQLite.execute(db, query, []).then(function (result) {
                if (result.rows.length) {
                    for (var i = 0; i < result.rows.length; i++) {
                        clienteselec.push(result.rows.item(i));
                    }
                } else {
                    console.log("no data found!");
                }
            }, function (err) {
                console.log("error" + err);
            });
        },
});

The view where the information will be displayed:

<ion-header>

  <ion-navbar>
    <ion-title>Instalacao</ion-title>
  </ion-navbar>

</ion-header>


<ion-content padding>
  <label class="item item-input">
      <span class="input-label">Cliente:</span>
      <input type="text" id="TxtCli" disabled />
  </label>
  <label class="item item-input">
      <span class="input-label">TC</span>
      <input type="text" id="TxtTC"/>
  </label>
  <label class="item item-input">
      <span class="input-label">Data:</span>
      <input type="text" id="TxtData" disabled />
  </label>
  <label class="item item-input">
      <span class="input-label">Hora:</span>
      <input type="text" id="TxtHora" disabled />
  </label>

  <div ng-controller="ClienteDetalheCtrl">
     <ion-item ng-repeat="inst in selecionaInstalacao">
         {{inst.TC}}, {{inst.posicao}}, {{inst.Rolo}}, {{inst.dataEquip}}
     </ion-item>
     <ion-item ng-show="!selecionaInstalacao.length">No events</ion-item>
  </div>
      <button ng-click="alteraInstalacao()">Altera</button>
</ion-content>

I am urgently seeking a solution to ensure that the page refresh functions correctly as I need to populate the grid below the textboxes. Any assistance would be greatly appreciated. Thank you.

Answer №1

After working diligently, I successfully resolved the issue. To assist those facing a similar problem, please refer to the correction provided below:

Initial Code Snippet:

.controller('ClienteCtrl', ['clientesFactory', '$scope', '$state', '$window', '$rootScope', function (clientesFactory, $scope, $state, $window, $rootScope) {
$scope.cadastraCliente = function (id, nome, TC) {
    $rootScope.idCliente = id;
    $rootScope.nomeCli = nome;
    $rootScope.TC = TC;

    if ($rootScope.TC === null) {
        $rootScope.TC = 1;
    } else {
        $rootScope.TC = $rootScope.TC + 1;
    }

    $state.transitionTo('tab.cliente-detalhe', {}, { reload: true, inherit: false });
};
    $window.location.reload();
}])

Updated Code Snippet:

.controller('ClienteCtrl', ['clientesFactory', '$scope', '$state', '$window', '$rootScope', function (clientesFactory, $scope, $state, $window, $rootScope) {
$scope.cadastraCliente = function (id, nome, TC) {
    $rootScope.idCliente = id;
    $rootScope.nomeCli = nome;
    $rootScope.TC = TC;

    if ($rootScope.TC === null) {
        $rootScope.TC = 1;
    } else {
        $rootScope.TC = $rootScope.TC + 1;
    }

    $state.transitionTo('tab.cliente-detalhe', {}, { reload: true, inherit: false });
};
}])

I hope this solution proves helpful to others facing a similar challenge. Gratitude to all who offered their assistance.

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

Unlocking the power of ReactJS: Utilizing context in the parent component

I am currently working on developing a foundational component that can manage UI themes. The theme is supposed to be passed to components through context, but I'm encountering an issue where the base component I've built does not seem to receive ...

Encountering difficulty linking MongoDB with Node.js

I recently delved into the world of MongoDB and I am currently attempting to locally host my Node.js application using MongoDB Server 6.0 (without relying on Mongoose or Atlas). After copying the async JavaScript code from the MongoDB documentation, I ens ...

Detecting page scrolling in Angular can be a challenging task

Having some issue with detecting scroll events in Angular. Here's the code snippet: @HostListener("window:scroll", []) onWindowScroll() { console.log("hello"); } Can anyone spot what I'm doing wrong? ...

Eliminate any blank spaces in the SELECT Angular application for IE-CSS

One issue I encountered is removing the default selected "SELECT" option from a select drop down on my webpage. Currently, I am using to remove it successfully in Chrome and Firefox browsers, but unfortunately IE does not respond to this method. I ha ...

The table will remain empty for eternity as the page is being loaded using ngRoute

Currently, I am utilising Angular routers. app.config(function($routeProvider) { $routeProvider .when('/comment/list', { templateUrl: 'commentList.htm', controller: 'mainController' }) }); ...

display the designated image as a priority

I am designing a loading screen for my website that includes the loading of multiple images, scripts, and other elements. While the HTML and CSS part is working well, I need to ensure that the "loading..." image is loaded before anything else on the page. ...

Comparing Ajax methods: Which one reigns supreme?

I am seeking advice on the best approach to handle a series of Ajax insert, update, and delete operations. Which method is more effective? Creating individual methods for each function (e.g., delete_foo, insert_foo, update_foo, delete_bar, insert_bar, ...

Service Worker in Workbox with Background Sync functionality

For the past few days, I have been utilizing Workbox and ensuring that I am setting it up correctly to generate a service worker from a source instead of letting Workbox do it for me. While everything seemed to be working fine, I recently attempted to int ...

We were caught off guard by the TypeScript error: an unexpected token showed up when we were expecting a constructor,

Trying to implement a function within a class in TypeScript. class Test { function add(x: number, y: number): number { return x + y; } } Encountering an error message stating: TypeScript Unexpected token, A constructor, method, access ...

Creating a Custom "Save As" Dialog in HTML5 and JavaScript for Downloading Files

I have developed a NodeJS/Express application that is capable of generating and downloading an Excel document (created using ExcelJS) when a user clicks on a button. Currently, the file gets automatically downloaded to the default download location of the ...

Create a few documents, and duplicate the remainder

I need help with a straightforward project. In my directory, I have some bash files and JavaScript files in the src/ folder. My aim is to transpile the JS files and copy over the rest of the files. Here's how my folders are structured: root |- dist ...

Receive updates from the backend GraphQL and display them on the frontend React application while executing a mutation

I recently implemented a mutation call from the frontend (react) to the backend, running 5 SQL query files. While the backend processes the queries, the frontend simply shows a "loading..." message. //frontend <Button onClick={()=>addData()} /> C ...

Navigating through a RealmObject and resetting an ArrayList attribute

I have a RealmResults<Section> containing a RealmList<Event> field that I need to clear for each Section. In my attempt (inside mRealm.executeTransaction) for (section : mSections) { section.getEvents().clear(); } and Iterator<Sectio ...

`Where can I find resources on connecting components in Angular 2?`

Exploring ways to enhance my website, I am considering allowing users to customize the theme according to their preferences. To start off, I decided to introduce a 'Dark theme' option. In order to implement this feature effectively, I am working ...

Issues with EventListeners in Internet Explorer

Similar Inquiry: Issue with MSIE and addEventListener in JavaScript? I am currently attempting to detect a close event on a popup window created by the parent page. The objective is for users to fill out a form and then, via a popup window, grant perm ...

Is there a Page Views tracker in sinatra?

Help needed with implementing a page views counter using Sinatra and Ruby. I attempted using the @@ variables, but they keep resetting to zero every time the page is reloaded... Here's an example: Appreciate any advice! ...

Resolving the transformClassesWithJarMergingForDebug Error issue

How can I fix the Error:Execution failed for task app:transformClassesWithJarMergingForDebug issue in Android Studio? Encountered com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: org/apache/http/Con ...

The Discord OAuth2 bot fails to assign roles to authenticated users

While working on OAuth2 login for my website, I encountered an issue. After a user successfully logs in through OAuth2, the bot should assign a role to them on my Discord server. However, when I tested the login process myself, the bot returned an error me ...

Retrieve the content of an element within a freshly launched window

I am looking to utilize JavaScript to open an html file and input some data into specific elements. My attempt so far has been: var info_window = window.open('info_print.html') info_window.document.getElementById('new_info').innerHTML ...

Is there a difference between innerHTML strings and their corresponding strings in JavaScript?

I am facing an issue with a code snippet that seems to have an unusual error. The following code is a simplified version to demonstrate the strange behavior. <html> <head> <script type = "text/javascript"> window.onload = fun ...