我正在嘗試編寫登錄用戶的帖子請求,但沒有任何作用。我不明白爲什麼,並會爲任何幫助感到高興!謝謝!!Angular - 無法發送POST請求登錄用戶,不知道什麼是錯的?
我的控制器:
'use strict';
app.controller('loginController', function($scope, $state, $http){
$scope.submitLogin=function(email,password)
return $http.post('/login', {email:$scope.email, password:$scope.password })
//因爲我有NG-模型=「電子郵件」 - 我實際上並不需要在$ scope.email通過,但只能用電子郵件傳遞?!在HTML的
.then(function(success){
if (sucess){
console.log(success)
$state.go('stories')
}
else {
console.log('error')
}
})
.catch(function(err){
console.log("bad")
})
})
部分:
<div class="form-group">
<label ng-model="email">email</label>
<input type="text" class="form-control" required />
</div>
<div class="form-group">
<label ng-model="password">password</label>
<input type="password" class="form-control" required />
</div>
<button type="submit" class="btn btn-block btn-primary" ng-click="submitLogin()">login</button>
</form>
國家:
'use strict';
app.config(function ($stateProvider) {
$stateProvider.state('login', {
url: '/login',
controller:'loginController',
templateUrl: '/browser/app/login/login.html'
});
});
您需要將ng-model =「email」放入您的輸入中而不是標籤中。 –
讓我知道當你把ng模型輸入到輸入時它是否仍然不起作用。 –
謝謝。它仍然無法正常工作,我得到這個奇怪的錯誤:錯誤:[ng:areq] http://errors.angularjs.org/1.3.20/ng/areq?p0=loginController&p1=not%20aNaNunction%2C%20got% 20定義 – javascript2016