2016-07-27 47 views
0

我是Ionic和angularjs中的新成員。我正嘗試從signin.html頁面獲取登錄(ng模型)數據(電子郵件&密碼),並使用POST方法調用API,但它不調用API。我爲此花了幾天時間。請幫幫我!通過REST API中的控制器傳遞的數據

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**** 


    }); 
+0

如何從signin.html頁面獲取ng-model值,並將其與API」post「方法綁定? –

+0

爲什麼不先創建一個合適的JSON對象,沒有字符串,然後根據需要將其轉換爲字符串.... – harishr

+0

您如何影響控制器到您的視圖?你有沒有定義控制器屬性的路由或你的dom中的ng-controller屬性?我懷疑你的控制器沒有與視圖鏈接 – Silvinus

回答

0

最後我創建API後弦與此... 數據:「JSON = { 「METHOD_NAME」 :「login」,「body」:{「login_with」:「2」,「facebook_id」:「」,「email」:「'+ scope.login.email +'」,「name」:「」,「password 「:」'+ $範圍。 「login}密碼''}}',

0
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! 
相關問題