J. Doe J. Doe - 4 months ago 13
PHP Question

Get values and pass to api ionic angularJS

I have a form:

<form name="loginform" novalidate class="css-form">
<label class="item item-input item-stacked-label">
<span class="input-label">Email</span>
<input type="email" name="email" ng-model="user.username" placeholder="Email" required>
<p class="error validationerror"
ng-show="loginform.email.$invalid && loginform.email.$touched">
Must be a valid email</p>
</label>
<label class="item item-input item-stacked-label">
<span class="input-label">Password</span>
<input type="password" name="password" ng-model="user.password" placeholder="Password" required>
<p class="error validationerror"
ng-show="loginform.password.$invalid && loginform.email.$touched">
Password is required</p>
</label>

</div>
{{value}}
<input type="submit" ng-click="Login(user)" class="button button-dark marginauto loginformbtn" value="Login">
</form>


and what I want to do is this I want to grab the user.username and the user.password and I want to pass them to a api I know how to grab them but I do not know how to send them as POST to the URL like with cURL in PHP.

here is the angular js code I have:

$scope.Login = function(user) {
$scope.value = {};
};


Please help thank you

Answer

To do $http.post method in angularjs

in your problem

$scope.login= function(user){

     var value = {
                    "UserName":user.username,
                    "PassWord":user.password
                 };


      $http.post("place your http service here",value)
            .success(function(res){
               console.log(res);
             })
            .error(function(res){
               console.log(res);
             });

To know more about $http look in the official document

Comments