skip to Main Content

I am new in Ionic and angularjs. I am trying to fetch login (ng-model) data (email&password) from signin.html page, and calling API with POST method.But it doesn’t call api. I spent couple of days for this. Please help me!

html

  <ion-view view-title="login">
    <ion-component>
    </br>

    <div class="list list-inset">
    <label class="item item-input">
    <input type="text" placeholder="First Name" ng-model="login.firstname">
    </label>
    <label class="item item-input">
    <input type="password" placeholder="Password" ng-model="login.password">
    </label>

    <label class="item item-input">
    <input type="text" placeholder="E-mail" ng-model="login.email">
    </label>

    <button class="button button-block button-balanced" data-ng-click="submit(login)">
    Login
    </button>
    <button class="button icon-left button-block ion-social-facebook button-positive">Login Facebook</button>

    <button class="button icon-left button-block ion-social-googleplus button-assertive">Login Google+</button>

    <a ng-href="#/signup"><button class="button button-clear button-positive">SignUp
    </button></a>
    </div>

    </ion-component>
    </ion-view>

app.js

  var app=angular.module('starter', ['ionic','ngCordova'])
    app.controller('loginCtrl', function($scope,$http){
    $scope.data=[];
    // $scope.logindata = {};
    // console.log (login);
    $scope.login={};
    //****login submit****
    $scope.submit=function(login){
    console.log(login);
    $scope.logincontet=console.log('logindata:'+login);
    //***api call***

    var local1='json={"method_name":"login","body":{"login_with":"2","facebook_id":"","email":';
    var local2=',"name":"",';
    var local3='"password":';
    var local4='}}';
    var req =
    {
    method: 'POST',
    url: "http://192.168.1.23/projects/veterinary/webservice/main.php",
    //data: 'json={"method_name":"login","body":{"login_with":"2","facebook_id":"","email":"$scope.login.email","name":"","password":"$scope.login.password"}}',
    data:local1 + $scope.login.email + local2 + local3 + $scope.login.password +local4,
    headers: {"Content-Type": "application/x-www-form-urlencoded"}
    };

    $http(req).success(function(data, status, headers, config)
    {
    console.log('Success',data);
    $scope.data=data.data;
    //success
    })
    .error(function(data, status, headers, config)
    {
    console.log('Error');
    });//error
    //*********
    window.location.href = "#/success.html";
    }
    //*****
    //****login api call****


    });

2

Answers


  1. Chosen as BEST ANSWER
    app.config(function($stateProvider, $urlRouterProvider){
    $stateProvider
    
    .state('login', {
    url: "/login",
    templateUrl: "templates/login.html",
    controller: 'loginCtrl'
    })
    
    .state('signup', {
    url: "/signup",
    templateUrl: "templates/signup.html",
    controller: 'signupCtrl'
    })
    
    
    
    // if none of the above states are matched, use this as the fallback
    $urlRouterProvider.otherwise('/login');
    
    });
    *********************
    Binding view and controller!
    

  2. Finally I created post api string with this…
    data: ‘json={“method_name”:”login”,”body”:{“login_with”:”2″,”facebook_id”:””,”email”:”‘+$scope.login.email+'” ,”name”:””,”password”:”‘+$scope.login.password+'”}}’,

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search