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

tablet size qualifiers not being used
Preferences & CheckBoxes
Debugger not stopping at breakpoints for developing android application using eclipse
Custom adapter: get item number of clicked item in inflated listview
LinearLayout won't display everything
Android Setting->Display… What type of menu is that?
How to use an Android stock app as a library in another custom Android app?
Flex Builder dateFormatter timezone offset
Android CustomListView overlapping other components
How to dynamically add LinearLayout on Android?
Problems running Sencha Touch / PhoneGap example code on android
Android WebServices with ksoap2
Error opening android camera for streaming video
Using a spinner to open up a new activity and displaying downloaded html data
Shared preferences in another activity/class
Is there anyway to get the Rect in which Bitmap is drawn on Android?

Categories

HOME
facebook-oauth
dns
github-for-windows
jax-rs
datastore
jmx
saml-2.0
oracle-apex-5
sublimetext
rds
crystal-reports-2013
odoo-8
lanczos
performancepoint
google-chrome-app
plist
rtf
gource
bitnami
altera
imessage
systemtime
bulletphysics
jackson-modules
linked-data
realm-mobile-platform
database-comparison
kodi
jmockit
playstation-portable
memory-address
least-squares
typesafe-config
tasm
magento-1.9.3
double-click
facebook-pixel
tf
yii2-user
er-diagram
check-mk
bbpress
type-theory
ampps
android-instrumentation
grails-plugin
qtplugin
xcode-server
x-tag
observablecollection
cda
fink
design-principles
phpgrid
atan2
terracotta
xenomai
fuelcms
mod-proxy
user-permissions
umlgraph
jbake
primitive-types
administration
teaspoon
entry-point
machine-instruction
universal-image-loader
alternate
mutual-authentication
multitasking
windows-phone-8-sdk
jeromq
ice-cube
font-awesome-4.0.0
extreme-programming
mkv
fragmenttransaction
jquery-blockui
dajaxice
correlated-subquery
inkcanvas
agility.js
promotion-code
listactivity
strsep
socketserver
load-time
instantiationexception
zen
echo3
mathematical-notation
flvplayback
appliance
pnrp

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