As a newcomer to AngularJS
and Ionic
, I am currently delving into Ionic 1. My current endeavor involves defining a function within my controller for a login view page that should only execute upon clicking the submit button. Here is the directive setup I have implemented:
<ion-view title="Login" id="page5">
<ion-content padding="true" class="has-header">
<h4 id="login-heading8" style="color:#000000;font-weight:400;">Please enter your phone number:</h4>
<form ng-submit="send()" id="login-form1" class="list">
<ion-list id="login-list1">
<label class="item item-input" id="login-input1">
<span class="input-label">Phone:</span>
<input type="tel" placeholder="" ng-model="formData.phoneNumber">
</label>
</ion-list>
<div class="spacer" style="height: 40px;"></div>
<input value="Submit" type="submit" id="login-button1" style="border-radius:1px 1px 1px 1px;" class="button button-positive button-block">
</form>
</ion-content>
</ion-view>
My solution involves creating a new function within my $scope
to prevent it from being called before the submit button is clicked. Here's a glimpse at the controller setup:
.controller('loginCtrl', ['$scope', '$stateParams', 'httpService',
function ($scope, $stateParams, httpService) {
$scope.formData = {phoneNumber : ""};
$scope.send= function(httpService){
httpService.getCall("http://localhost:8000/Hermerest/web/app_dev.php/api/parents?telephone=" + $scope.formData, loginCtrlCallback);
}
}])
I've attempted to utilize a factory method to streamline my code and avoid redundancies. However, injecting httpService as a parameter into $scope.send()
seems to be causing issues as it is recognized as undefined. Here's a snippet of my factory code:
.factory('httpService', function($http){
return {
getCall: function(url, callback){
$http.get(url)
.success(function (response) {
alert(response);
//callback(response);
})
},
postCall: function(url, data, callback){
$http.post(url, data)
.success(function (response) {
alert(response);
//callback(response);
})
}
}
})
Being relatively new to this, I am open to any suggestions or fixes that could potentially resolve this issue. Thank you in advance for your assistance!