HTML
<form id="newSaveForm">
<div class="item">
<div class="list">
<label class="item item-input">
<input type="date" ng-model="dateSave" placeholder="Date" required>
</label>
</div>
<div class="list">
<label class="item item-input">
<input type="number" ng-model="moneySave" placeholder="Deposit?" required>
</label>
</div>
<button class="button button-block button-balanced ion-android-checkbox-outline" data-ng-click="addMoney(dateSave,moneySave)" ng-disabled="buttonDisabled"> Save </button>
</div>
</form>
JavaScript
.controller('saveCtrl', function($scope, $state, $http, $filter) {
getAll();
$scope.addMoney = function(tgl, jml) {
$scope.buttonDisabled = true;
$http.post("http://localhost/mymoney/insert.php?jml=" + jml + "&tgl=" + conv_date(tgl)).success(function(response) {
getAll();
$scope.dateSave = "";
$scope.moneySave = "";
console.log('Success Insert');
}).finally(function() {
$scope.buttonDisabled = false;
});
};
function getAll() {
$http.get("http://localhost/mymoney/deposit.php")
.then(function(response) {
$scope.listDeposit = response.data.records;
});
};
function conv_date(tgl) {
return $filter('date')(tgl, 'yyyy-MM-dd');
};
});
Why when I click addMoney function twice I get 2 results in one time
Related
I'm trying to create a user and register him with firebase/angularfire, i think i'm following the angularfire documentation but i have "createUserWithEmailAndPassword failed: First argument "email" must be a valid string." message.
enter code here
<ion-view>
<ion-content padding="false">
<div class="list list-inset">
<label class="item item-input">
<input type="text" ng-model="email" placeholder="e-mail">
</label>
<label class="item item-input">
<input type="text" ng-model="password" placeholder="Password">
</label>
</div>
<div class="item item-divider text-center">
<a href="" class="button button-positive button-small" ng-click="createUser()">
Enregistrez
</a>
</div>
</ion-content>
</ion-view>
'use strict';
app
.factory("Auth", ["$firebaseAuth",
function($firebaseAuth) {
console.log("factory");
return $firebaseAuth();
console.log("factory");
}
])
.controller('homepageIndex',function($scope){
})
.controller('homepageSignUp', ['$scope', 'Auth', function($scope, Auth) {
$scope.createUser = function() {
// Create a new user
Auth.$createUserWithEmailAndPassword($scope.email, $scope.password)
.then(function(firebaseUser) {
}).catch(function(error) {
console.log("error");
});
};
}
]);
if it can help somebody i found the way like this, i dont know if it's the best way:
<ion-view>
<ion-content padding="false">
<div class="list list-inset">
<label class="item item-input">
<input type="text" ng-model="newUser.email" placeholder="e-mail">
</label>
<label class="item item-input">
<input type="text" ng-model="newUser.password" placeholder="Password">
</label>
</div>
<div class="item item-divider text-center">
<a href="" class="button button-positive button-small" ng-click="registerUser(newUser)">
Enregistrez
</a>
</div>
</ion-content>
</ion-view>
'use strict';
app.factory("Auth", ["$firebaseAuth",
function ($firebaseAuth) {
return $firebaseAuth();
}
]);
app.controller('homepageIndex', function ($scope) {
});
app.controller('homepageSignUp', ['$scope', 'Auth', function ($scope, Auth) {
var newUser = $scope.newUser = { email: "", password: "" };
$scope.registerUser = function () {
Auth.$createUserWithEmailAndPassword(newUser.email, newUser.password)
.then(function (firebaseUser) {
console.log("yas", firebaseUser);
}).catch(function (error) {
console.log("error");
});
};
}
]);
in this code of HTML, we get input text value and send to the Angular controller
so they get to work as defined in code.
<div class="row" ng-controller="RegionController">
<div class="col-lg-12" >
<div class="hpanel">
<div class="panel-heading">
<!-- <div panel-tools></div> -->
<h2>Region Master Entry</h2>
</div>
<div class="panel-body">
<!--change form name,and submit controller name-->
<form role="form">
<div class="form-group">
<label class="col-sm-2 control-label">Region Name</label>
<div class="col-sm-10">
<input type="text" placeholder="please enter Region name" class="form-control m-b" required name="Region Name" ng-model="formRegionData.region_name" >
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">Region Code</label>
<div class="col-sm-10">
<input type="text" placeholder="please enter Region code" class="form-control m-b" required name="Region Code" ng-model="formRegionData.region_code">
</div>
</div>
<div class="form-group">
<div class="col-sm-3">
<label>Active</label>
</div>
<div class="checkbox checkbox-success col-sm-9">
<input id="checkbox3" type="checkbox" checked="" ng-model="formRegionData.status">
<label for="checkbox3">
</label>
</div>
</div>
<div class="form-group">
<div class="col-sm-4"></div>
<div class="col-sm-8">
<button class="btn btn-sm btn-primary btn-xl text-right" type="submit" ng-click="createRegion()"><strong> Save Region </strong></button>
</div>
</div>
{{formRegionData | json}}
</form>
</div>
</div>
</div>
</div>
"{{formRegionData | json}}" this will return in HTML input text result of but not send data to the controller
in Controller the code is written as
.controller('RegionController', function( $scope , regionService) {
$scope.createRegion = function() {
debugger;
vm.processing = true;
vm.message = '';
console.log(formRegionData);
regionService.SaveRegion( formRegionData )
.then(function(data) {
debugger;
//console.log(data);
//.success(function(data) {
vm.processing = false;
vm.storyData = {};
vm.message = data.message;
});
}
})
and my service to work according to Controller
.factory('regionService',function($http ){
var regionFactory = {};
regionFactory.SaveRegion = function(formRegionData) {
debugger;
return $http.post('/api/region/', formRegionData);
}
return regionFactory;
});
You have missed $scope
$scope.createRegion = function() {
debugger;
$scope.processing = true;
$scope.message = '';
console.log($scope.formRegionData);
regionService.SaveRegion($scope.formRegionData )
.then(function(data) {
debugger;
//console.log(data);
//.success(function(data) {
$scope.processing = false;
$scope.storyData = {};
$scope.message = data.message;
});
}
})
and remove ng-click="createRegion()" in your button control and add this code in your form tag by ng-submit. like,
<form ng-submit="createRegion()" role="form">
You have missed of $scope in form region data
Here is the link Jsfiddle
JS
angular.module('myApp', ['ngStorage'])
.controller('RegionController', function($scope, regionService) {
var vm = this;
$scope.createRegion = function() {
debugger;
vm.processing = true;
vm.message = '';
regionService.SaveRegion($scope.formRegionData)
.then(function(data) {
debugger;
//console.log(data);
//.success(function(data) {
vm.processing = false;
vm.storyData = {};
vm.message = data.message;
});
}
}).factory('regionService', function($http) {
var regionFactory = {};
regionFactory.SaveRegion = function(formRegionData) {
debugger;
return $http.post('/api/region/', formRegionData);
}
return regionFactory;
});
im having problem for $http.get to retrieve json from input fields value from view. heres my code
My form
<div class="container">
<div class="col">
<div class="app-logo"><img src="img/logo.svg"></div>
<div class="list list-inset removePM">
<label class="item item-input">
<input type="text" ng-model="user.username" placeholder="NRIC" >
</label>
<label class="item item-input">
<input type="password" ng-model="user.password" placeholder="Password" > </label>
</div>
<div class="loginButton"><button class="button ion-unlocked button-block button-balanced custom-button" ng-click="login(user);"> Login </button> </div>
</div>
My controller
angular.module('starter.controllers', [])
.controller('LoginCtrl', function($scope, LoginService,
$ionicPopover, $timeout, $location, $ionicPopup, Profiles){
$scope.login = function (user) {
Profiles.grab(user);
};
})
My Services
.factory('Profiles', function($http, $location, sessionService, $window, LoginService) {
var profiles = {content:null};
$http.get('http://192.168.0.113/soap-request/soap.php?username='+ user.username +'&password=' + user.password +'').success(function(data) {
profiles.content = data;
return true;
});
grab: function(data, $http) {
return profiles;
}
});
I have a very simple form template and controller. But i'm unable to call a function from within the onSubmit scope function. Controller is:
angular
.module('myApp')
.controller('registerUserCtrl', registerUserCtrl);
function registerUserCtrl($scope, $location, $window, authenticationService, $http, vcRecaptchaService){
$scope.pageHeader = {
title: 'Register',
};
$scope.register = function (data) {
console.log('in scope.register ');
userService.register(data)
.success(function(data) {
console.log('setting to true.....');
authenticationService.isLoggedIn = true;
authenticationService.user = data.user;
authenticationService.token = data.token;
$location.path("/");
}).error(function(status, data) {
console.log(status);
console.log(data);
$scope.formError = "This email has already been taken";
});
}
$scope.onSubmit = function () {
console.log('in onSubmit');
//N.B. Need to veriify this
var response = vcRecaptchaService.getResponse();
$scope.formError = "";
if(!$scope.formData || !$scope.formData.email || !$scope.formData.password) {
$scope.formError = "All fields required, please try again";
return false;
} else {
console.log('$scope is ');
console.log($scope);
$scope.register($scope.formData);
}
};
}
And template is:
<div id="register-wrapper">
<form class="form-horizontal" role="form" ng-submit="onSubmit()">
<div role="alert" ng-show="formError" class="alert alert-danger">{{ formError }}</div>
<div class="form-group">
<label for="inputEmail" class="col-sm-4 control-label">Email</label>
<div class="col-sm-4">
<input type="email" class="form-control" id="inputEmail" placeholder="Email" ng-model="formData.email">
</div>
</div>
<div class="form-group">
<label for="inputPassword" class="col-sm-4 control-label">Password</label>
<div class="col-sm-4">
<input type="password" class="form-control" id="inputPassword" placeholder="Password" ng-model="formData.password">
</div>
</div>
<div vc-recaptcha key="'6Lf6aQsTAAAAAACdCxN2FqHHKpz0RyF9jMJsn6h4'"></div>
<div class="form-group">
<div class="col-sm-offset-4 col-sm-10">
<button type="submit" class="btn btn-default">Register</button>
</div>
</div>
</form>
</div>
I always end up with:
undefined is not a function
at the $scope.register($scope.formData); line. I've done this many times before, but somehow now its not working...
You need to inject userSevice in your controller as dependency
angular
.module('myApp')
.controller('registerUserCtrl', registerUserCtrl);
function registerUserCtrl($scope, $location, $window, authenticationService,
$http, vcRecaptchaService, userSevice)
{
we have controller which has ng-include to load an external html. now i want to access a control value in parent.
my template is MainMenuCreate
#{
Layout = null;
}
<div >
<h2>{{Headtitle}}</h2>
<p>
<div style="width:200px;">MainMenuId :</div>
<input type="text" name="MainMenuId" id="MainMenuId" data-ng-model="MainMenuId" />
</p>
<p>
<div style="width:200px;">MainMenu :</div>
<input type="text" name="MainMenu" id="MainMenu" data-ng-model="MainMenu" />
</p>
<p>
<div style="width:200px;">PageTitle :</div>
<input type="text" name="PageTitle" id="PageTitle" data-ng-model="PageTitle" />
</p>
<input type="button" name="btnSave" id="btnSave" value="Save" ng-click="Save()" />
and my main page is
<div data-ng-app="MainMenuModule">
<div data-ng-controller="MainMenuController">
<div data-ng-include="'MainMenuCreate'" >
</div>
{{MainMenuId}}
</div>
</div>
and controller is
app.controller('MainMenuController', function ($scope, MainMenuService) {
$scope.Save = function () {
var MainMenuRecord =
{
MainMenuId: $scope.MainMenuId,
MainMenu: $scope.MainMenu,
PageTitle: $scope.PageTitle
};
var promisePost = MainMenuService.post(MainMenuRecord);
promisePost.then(function (pl) {
$scope.MainMenu = pl.data.MainMenu;
loadRecords();
}, function (err) {
console.log("Err" + err);
});
}
});
when i call this save method then $scope.MainMenuId shows undefined
<div style="width:200px;">MainMenuId :</div>
<input type="text" name="MainMenuId" id="MainMenuId" data-ng-model="obj.MainMenuId" />
<div style="width:200px;">MainMenu :</div>
<input type="text" name="MainMenu" id="MainMenu" data-ng-model="obj.MainMenu" />
<div style="width:200px;">PageTitle :</div>
<input type="text" name="PageTitle" id="PageTitle" data-ng-model="obj.PageTitle" />
</div>
<input type="button" name="btnSave" id="btnSave" value="Save" ng-click="Save(obj)" />
app.controller('MainMenuController', function ($scope, MainMenuService) {
$scope.obj = {};
$scope.Save = function (obj) {
var MainMenuRecord =
{
MainMenuId: obj.MainMenuId,
MainMenu: obj.MainMenu,
PageTitle: obj.PageTitle
};
var promisePost = MainMenuService.post(MainMenuRecord);
promisePost.then(function (pl) {
$scope.MainMenu = pl.data.MainMenu;
loadRecords();
}, function (err) {
console.log("Err" + err);
});
}
});