android


ng click not calling the function --very new to angular and ionic


trying to insert data to the sqlite db and the data is static that i am passing it through the function but ng click is not working. as i am new to this so please answer in details...thanks in advance.
//this is my module
var db=null;
var myApp=angular.module('starter', ['ionic','ngCordova'])
.run(function($ionicPlatform,$cordovaSQLite) {
$ionicPlatform.ready(function() {
if(window.cordova && window.cordova.plugins.Keyboard) {
// Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
// for form inputs)
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
// Don't remove this line unless you know what you are doing. It stops the viewport
// from snapping when text inputs are focused. Ionic handles this internally for
// a much nicer keyboard experience.
cordova.plugins.Keyboard.disableScroll(true);
}
if(window.StatusBar) {
StatusBar.styleDefault();
}
db = $cordovaSQLite.openDB({name:"my.db",location:'default'});
$cordovaSQLite.execute(db,"CREATE TABLE IF NOT EXISTS user(id integer primary key, username text, password text)")
});
})
//this is my controller
myApp.controller('SignInCtrl',['$cordovaSQLite', function($scope, $cordovaSQLite) {
$scope.insert=function(username,password){
alert("hii");
var query="INSERT INTO user(username,password) VALUES(?,?)";
$cordovaSQLite.execute(db.query,[username,password]).then(function(res){
console.log("Insert ID ->" + res.insertId);
},
function(err){
console.error(err);
});
}
$scope.select = function(username) {
var query = "SELECT username, password FROM user WHERE username = ?";
$cordovaSQLite.execute(db, query, [password]).then(function(res) {
if(res.rows.length > 0) {
console.log("SELECTED -> " + res.rows.item(0).username + " " + res.rows.item(0).password);
} else {
console.log("No results found");
}
}, function (err) {
console.error(err);
});
}
}])
//this is my page
<ion view view-title="Sign-In" name="Login-View">
<ion content class="padding">
<div class="list list-inset">
<label class="item item-input">
<input type="text" placeholder="Username" ng-model="data.username">
</label>
<label class="item item-input">
<input type="password" placeholder="Password" ng-model="data.password"></input>
</label>
</div>
</ion>
<button class="button button-block button-positive" ng-click="login(data)">Login</button>
</ion>
<br>
Sign Up
Forgot Password
Order page
<button class="button button-block button-positive" ng-click="insert('ran','badu')">insert</button>
<button class="button button-block button-positive" ng-click="select('ran')">select</button>
//this is my index page
<body ng-app="starter">
<ion-header-bar class="bar-positive">
<h1 class="title">Billing system</h1>
<button class="button icon ion-navicon"></button>
<button class="button icon ion-search"></button>
</ion-header-bar>
<!-- <ion-content > -->
<!-- <P>I am in index</P>
Loginpage -->
<!-- </ion-content> -->
<ion-nav-view class="slide-left-right"></ion-nav-view>
</body>
//this is my route
.config(function($stateProvider,$urlRouterProvider) {
$stateProvider
.state('Login',{
url:'/Login',
templateUrl:'templates/Login.html',
controller:'SignInCtrl'
})
.state('Signup',{
url:'/Signup',
templateUrl:'templates/Signup.html',
controller:'SignInCtrl'
})
.state('ForgotPassword',{
url:'/ForgotPassword',
templateUrl:'templates/ForgotPassword.html',
controller:'SignInCtrl'
})
.state('orderpage',{
url:'/orderpage',
templateUrl:'templates/orderpage.html',
controller:'SignInCtrl'
})
$urlRouterProvider.otherwise('/Login');
})
You have an error with SignInCtrl declaration. Change this line of code
myApp.controller('SignInCtrl',['$cordovaSQLite', function($scope, $cordovaSQLite)
with
myApp.controller('SignInCtrl',['$scope','$cordovaSQLite', function($scope, $cordovaSQLite)
The problem here is that you use inline dependency injection and the order is important
Looking at your code the login() method does not exist in your SignIn controller try adding the login method to the controller
myApp.controller('SignInCtrl', ['$cordovaSQLite', function ($scope, $cordovaSQLite) {
$scope.insert = function (username, password) {
alert("hii");
var query = "INSERT INTO user(username,password) VALUES(?,?)";
$cordovaSQLite.execute(db.query, [username, password]).then(function (res) {
console.log("Insert ID ->" + res.insertId);
},
function (err) {
console.error(err);
});
}
$scope.select = function (username) {
var query = "SELECT username, password FROM user WHERE username = ?";
$cordovaSQLite.execute(db, query, [password]).then(function (res) {
if (res.rows.length > 0) {
console.log("SELECTED -> " + res.rows.item(0).username + " " + res.rows.item(0).password);
} else {
console.log("No results found");
}
}, function (err) {
console.error(err);
});
}
$scope.login = function(data){
//Add Login Logic ....:)
console.log(data)
}
}])

Related Links

Android notification addAction not launching broadcast
Web API call without setOnScrollListener() of Listview pagination in android
Android CursorAdapter: Moving db access to worker thread?
TabLayout indicator doesn't work in PreLollipop emulator
Android Studio gradle build for android compatible Android – 5.0 Lollipop etc
Reuse a inflated view, without inflating more than once
Places API for Android
Cannot launch AVD in emulator in android studio 2.2
How to Start Activity from Bottom Navigation Drawer?
MQTT Eclipse Paho Android App basic
Live wallpaper not change in Android device when set another live wallpaper
How to add image taken, from camera intent to the gallery?
Google Sheets API V4 for reading public sheet with less steps
Android player which support Wowza (RTSP/RTMP) Audio streaming
Mapbox for Android: Change map input based on current zoom level
Multipart file upload using okhttp generated by postman

Categories

HOME
httparty
spark-streaming
alexa-skills-kit
angular2-material
jwplayer
composite-primary-key
socket.io
shiro
ms-access-2016
database-normalization
tivoli
vxml
spring-session
angularfire2
character
teechart
augeas
little-proxy
openpyxl
android-securityexception
opengl-es-3.0
spring-social
openbugs
speech-synthesis
intercom
selenium-ide
do-while
atlassian-stash
powershell-v5.0
android-7.0-nougat
google-picker
pyramid
replication
articulate-storyline
highstock
xcode-ui-testing
angularjs-components
progress-bar
spotipy
errbot
cppreference
custom-controls
laravel-eloquent
wacom
papaparse
keras-layer
joomla2.5
yowsup
raft
imagenet
git-rewrite-history
jpad
reactivekit
css-position
demo
p4merge
kill
cnc
activeperl
pair-programming
static-cast
modelsim
git-flow
boo
oozie-coordinator
pybrain
baidu
cvxpy
stripe-connect
custom-lists
winusb
pacemaker
swizzling
lua-telegram-bot
project-organization
createprocess
ascii-art
rasterize
spring-retry
sciruby
roadkill-wiki
phonertc
zen-cart
extjs-grid
mod-proxy
uncompress
liquid-layout
mruby
mobility
reflector
jquery-slider
twitter-bootstrap-rails
android-audiorecord
openargs
light
embedded-fonts
css-reset
wp7test
superscrollorama
windows-98
android-loadermanager
cross-database
hibernateexception
pinch
user-tracking
android-holo-everywhere
xui
codebase
svk
cruisecontrol.rb
skype4java

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App