控制器:
.controller('registerCtrl', ['$scope', '$state', 'nicService','$cordovaSQLite', function ($scope, $state, nicService,$cordovaSQLite) {
$scope.addRegister = function () {
nicService.setData('nic', { nic: null });
$state.go('addregister');
};
$scope.editregister = function (nic) {alert(nic)
nicService.setData('nic', { nic: nic });//alert(nic);
$state.go('addregister');
};
$scope.reg = {};
$scope.searchRegister = function () {
var query = "select * from Register ORDER BY codes ASC";
$cordovaSQLite.execute(db, query).then(function (res) {
var result = "";
if (res.rows.length != 0) {
for (var i = 0; i < res.rows.length; i++) {
if (res.rows.item(i).state == "A") {//background-color:#ddd;
result += "<div class='' style='border: #ddd 1px solid;'>";
result += "<div class='row'>";
result += "<div class='.col col-50'><p>"+res.rows.item(i).codes+"</p></div>";
result += "<div class='.col col-50'><p>"+res.rows.item(i).name+"</p></div>";
result += "</div>";
result += "<div class='row'>";
result += "<div class='.col col-50'><p>"+res.rows.item(i).remark+"</p></div>";
result += "<i class='button button-small icon ion-edit' ng-click='editmemberdetail(" + res.rows.item(i).id + ")'></i><i class='button button-small icon ion-eye' ng-click='viewmemberdetail(" + res.rows.item(i).id + ")'></i></div>";
result += "</div>";
result += "</div>";
} else {
result += "<div class='' style='border: red 1px solid;'>";
result += "<div class='row'>";
result += "<div class='.col col-50'><p>"+res.rows.item(i).codes+"</p></div>";
result += "<div class='.col col-50'><p>"+res.rows.item(i).name+"</p></div>";
result += "</div>";
result += "<div class='row'>";
result += "<div class='.col col-50'><p>"+res.rows.item(i).remark+"</p></div>";
result += "<div class='.col col-50'><i class='button button-small icon ion-edit' ng-click='editmemberdetail(" + res.rows.item(i).id + ")'></i><i class='button button-small icon ion-eye' ng-click='viewmemberdetail(" + res.rows.item(i).id + ")'></i></div>";
result += "</div>";
result += "</div>";
}
}
} else {
result += "<div class='row' style='border:#ddd 0px solid;'>Register Panel Is Empty</div>";
}
$scope.reg.title = result;
}, function (err) {//alert(err);
console.error(err);
});
};
$scope.searchtxtRegister = function () {
var query = "select * from Register where codes like ? ORDER BY codes ASC";
//$cordovaSQLite.execute(db,"delete from Member");
$cordovaSQLite.execute(db, query, [$scope.reg.code]).then(function (res) {
if (res.rows.length !== 0) {
var result = "";
for (var i = 0; i < res.rows.length; i++) {
if (res.rows.item(i).state == "A") {//background-color:#ddd;
result += "<div class='' style='border: #ddd 1px solid;'>";
result += "<div class='row'>";
result += "<div class='.col col-50'><p>"+res.rows.item(i).codes+"</p></div>";
result += "<div class='.col col-50'><p>"+res.rows.item(i).name+"</p></div>";
result += "</div>";
result += "<div class='row'>";
result += "<div class='.col col-50'><p>"+res.rows.item(i).remark+"</p></div>";
result += "<div class='.col col-50'><i class='button button-small icon ion-edit' ng-click='editregister(" + res.rows.item(i).id + ")'></i></div>";
result += "</div>";
result += "</div>";
} else {
result += "<div class='' style='border: red 1px solid;'>";
result += "<div class='row'>";
result += "<div class='.col col-50'><p>"+res.rows.item(i).codes+"</p></div>";
result += "<div class='.col col-50'><p>"+res.rows.item(i).name+"</p></div>";
result += "</div>";
result += "<div class='row'>";
result += "<div class='.col col-50'><p>"+res.rows.item(i).remark+"</p></div>";
result += "<div class='.col col-50'><i class='button button-small icon ion-edit' ng-click='editregister(" + res.rows.item(i).id + ")'></i></div>";
result += "</div>";
result += "</div>";
}
}
$scope.reg.title = result;
} else {
$scope.searchRegister();
}
}, function (err) {
alert(err);
console.error(err);
});
};
}])
.directive('dirc', function ($compile, $parse) {
return {
restrict: 'E',
link: function (scope, element, attr) {
scope.$watch(attr.content, function () {
element.html($parse(attr.content)(scope));
$compile(element.contents())(scope);
}, true);
}
}
})
HTML:
<dirc id="dirc" content="reg.title"></dirc>