我是AngularJS的新手,并且在解决一些小问题时遇到了很多问题。 当我的视图刷新时,这会丢失配置。让我解释一下。我在视图的顶部有一个标签,下面有一些标签和texbox。当我的代码从sqlite中保存一些小配置时,离子忘记了标签并且对象上升,被标签隐藏。
按照用于调用sqlite的代码。
控制器
.controller('ClienteDetalheCtrl', ['clientesFactory', '$scope', '$state', '$window', '$rootScope', function (clientesFactory, $scope, $state, $window, $rootScope) {
buscaEquipamento();
alteraData();
function buscaEquipamento() {
clientesFactory.selectTodos('equipamento');
$scope.selecionaInstalacao = clienteselec;
}
}
sqlite叫:
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);
});
},
});
将显示信息的视图:
<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>
我需要在刷新页面时使其工作,因为我需要在文本框下面填充网格。 如果有人能帮助我,我将非常感激。谢谢大家。
答案 0 :(得分:0)
最后我解决了这个问题。对于能够遇到相同问题的人,请遵循更正。
之前的代码:
.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();
}])
更正后的代码:
.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 });
};
}])
我等着帮助任何人解决问题。感谢所有试图帮助我的人。