Faizah Pratiwi Faizah Pratiwi - 1 year ago 93
AngularJS Question

Button cant work

i want to make login with ionic and angularjs. when i'm finish my code and run to my browser, the button can't work. anyone can help me? i'm new with ionic

my login view :

<!DOCTYPE html>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">

<link rel="manifest" href="manifest.json">

<link href="lib/ionic/css/ionic.css" rel="stylesheet">
<link href="css/style.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>
<body ng-app="apps" ng-controller="PostController as postCtrl">
<ion-view view-title="Please Sign in">
<ion-content class="padding">
<div class="list">
<label class="item item-input">
<input type="text" placeholder="Name" ng-model="postCtrl.inputData.username">
<label class="item item-input">
<input type="password" placeholder="Password" ng-model="postCtrl.inputData.password">
<div class="alert alert-danger" role="alert" ng-show="errorMsg">{{errorMsg}}</div>
<button class="button button-full button-balanced" ng-click="postForm">Sign In</button>

module & controller :
angular.module('starter', ['ionic'])

.run(function($ionicPlatform) {
$ionicPlatform.ready(function() {
if(window.cordova && window.cordova.plugins.Keyboard) {


if(window.StatusBar) {

.controller('PostController', ['$scope', '$http', function($scope, $http) {

$scope.postForm = function() {

var encodedString = 'username=' +
encodeURIComponent($scope.inputData.username) +
'&password=' +

method: 'POST',
url: 'check-login.php',
data: encodedString,
headers: {'Content-Type': 'application/x-www-form-urlencoded'}
.success(function(data, status, headers, config) {
if ( data.trim() === 'correct') {
window.location.href = 'home.html';
} else {
$scope.errorMsg = "Login not correct";
.error(function(data, status, headers, config) {
$scope.errorMsg = 'Unable to submit form';


php file :

if ( $_POST['username'] === 'Test' &&
$_POST['password'] === '1234' ) {
echo 'correct';
} else {
echo 'wrong';


Answer Source

Try by making () after function in ng-click like this :

<button class="button button-full button-balanced" ng-click="postForm()">Sign In</button>

Let me know.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download