I am a ionic newbie, and I have done some slight angular js work, so I have tried to do some extensive research on the Net before coming here. I've also read a lot of tutorials and watched a lot of youtube videos to try and help. This brought me to the site listed: http://devdactic.com/simple-login-example-with-ionic-and-angularjs/
I followed the directions for making a simple login app. This app looks for a particular username/password combo and returns a success or failure. Once I get this working, my goal is to then change the app to call a restful web-service of OpenAM, passing in the username/password, but lets get this simple thing working first.
So, after following the directions, the screen looks great. Sometimes in the username/password textbox, I see almost like a "UUsername" or "PPassword" in the text boxes.
BTW, I create the ionic app from the command-line, removed all the plugins, and then I used the Eclipse JBoss Tools to Import the Cordova Project, then I finally ran the app with "Run with CordovaSim ..."
So, the app starts running and looks great. Once I click into the Username or Password text box, the app then starts to generate messages such as:
Outstanding resource locks detected:
D3D Vram Pool: 53,685,852 used (10.0%), 67,108,864 target (12.5%), 536,870,912 max
142 total resources being managed
average resource age is 113.0 frames
0 resources at maximum supported age (0.0%)
25 resources marked permanent (17.6%)
26 resources have had mismatched locks (18.3%)
26 resources locked (18.3%)
48 resources contain interesting data (33.8%)
0 resources disappeared (0.0%)
So, here is the code for: index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
<title></title>
<link href="lib/ionic/css/ionic.css" rel="stylesheet">
<link href="css/style.css" rel="stylesheet">
<!-- IF using Sass (run gulp sass first), then uncomment below and remove the CSS includes above
<link href="css/ionic.app.css" rel="stylesheet">
-->
<!-- ionic/angularjs js -->
<script src="lib/ionic/js/ionic.bundle.js"></script>
<!-- cordova script (this will be a 404 during development) -->
<script src="cordova.js"></script>
<!-- your app's js -->
<script src="js/app.js"></script>
<script src="js/controllers.js"></script>
<script src="js/services.js"></script>
</head>
<body ng-app="starter">
<!--
The nav bar that will be updated as we navigate between views.
-->
<ion-nav-bar class="bar-stable">
<ion-nav-back-button>
</ion-nav-back-button>
</ion-nav-bar>
<!--
The views will be rendered in the <ion-nav-view> directive below
Templates are in the /templates folder (but you could also
have templates inline in this html file if you'd like).
-->
<ion-nav-view></ion-nav-view>
</body>
</html>
In the template directory, we have: login.html
<ion-view view-title="AGMednet Login" 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">
</label>
</div>
<button class="button button-block button-calm" ng-click="login()">Login</button>
</ion-content>
</ion-view>
And here we have the app.js:
angular.module('starter', ['ionic'])
.run(function($ionicPlatform) {
$ionicPlatform.ready(function() {
// Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
// for form inputs)
if(window.cordova && window.cordova.plugins.Keyboard) {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
}
if(window.StatusBar) {
StatusBar.styleDefault();
}
});
})
.config(function($stateProvider, $urlRouterProvider) {
$stateProvider
.state('login', {
url: '/login',
templateUrl: 'templates/login.html'
});
$urlRouterProvider.otherwise('/login');
});
The controller.js:
angular.module('starter.controllers', [])
.controller('LoginCtrl', function($scope, LoginService, $ionicPopup, $state) {
$scope.data = {};
$scope.login = function() {
LoginService.loginUser($scope.data.username, $scope.data.password).success(function(data) {
$state.go('tab.dash');
}).error(function(data) {
var alertPopup = $ionicPopup.alert({
title: 'Login failed!',
template: 'Please check your credentials!'
});
});
}
});
And the service.js:
angular.module('starter.services', [])
.service('LoginService', function($q) {
return {
loginUser: function(name, pw) {
var deferred = $q.defer();
var promise = deferred.promise;
if (name == 'user' && pw == 'secret') {
deferred.resolve('Welcome ' + name + '!');
} else {
deferred.reject('Wrong credentials.');
}
promise.success = function(fn) {
promise.then(fn);
return promise;
}
promise.error = function(fn) {
promise.then(null, fn);
return promise;
}
return promise;
}
}
});