仍然在學習與離子在一起的mysql並試圖創建一個遠程數據庫的登錄表單,面臨一個問題,我得到一個錯誤「TypeError:無法讀取屬性'用戶名'未定義「TypeError:無法讀取未定義的屬性「用戶名」
下面是我的代碼
的login.html
<ion-header-bar align-title="center" class="bar-balanced">
<h1 class="title">Onseral</h1>
</ion-header-bar>
<ion-view>
<ion-content class="padding has-header">
<ion-list>
<ion-item>
<input type="text" ng-model="username" placeholder="Username">
</ion-item>
<ion-item>
<input type="password" ng-model="password" placeholder="Password">
</ion-item>
</ion-list>
<button nav-clear class="button button-block button-balanced" ng-click="LogIn()">Login</button>
</ion-content>
</ion-view>
controller.js
angular.module('ionicApp.controllers', [])
.controller('AppCtrl', function($scope) {
})
.controller('LoginCtrl', function($scope, $state, $http, $ionicPopup) {
$scope.LogIn = function() {
var request = $http({
method: "post",
url: "http://www.mywebsite.com/api/login.php",
data: {
username: $scope.username,
password: $scope.password
},
headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
});
/*Successful HTTP post request or not */
request.success(function (data){
if (data == '1'){
console.log('test success');
}
else {
console.log('test failed');
console.log($scope.username);
}
})
}
});
個
app.js
angular.module('ionicApp', ['ionic','ionicApp.controllers'])
.config(function($stateProvider, $urlRouterProvider) {
$stateProvider
.state('app', {
url: "/app",
abstract: true,
templateUrl: "templates/menu.html",
controller: 'AppCtrl'
})
.state('login', {
url: "/login",
templateUrl: "templates/login.html",
controller: 'LoginCtrl'
});
// if none of the above states are matched, use this as the fallback
$urlRouterProvider.otherwise('/login');
});
它只是無法得到從login.html的用戶名,我失去了什麼嗎?
你的代碼在哪裏拋出錯誤? – devqon
console.log($ scope.username); –
所以你的意思是'$ scope'在該行中是未定義的?那真的很奇怪 – devqon