我们可以使用输入数据在 HTML 文件中将其作为参数传递 w 使用 ng-model 绑定输入字段的值。
<input type="text" placeholder="Enter your Email" ng-model="email" required>
<input type="text" placeholder="Enter your password " ng-model="password" required>
并且在 js 文件中 w 使用 $scope 来访问这些数据:
$scope.email="";
$scope.password="";
控制器功能将是这样的:
var app = angular.module('myApp', []);
app.controller('assignController', function($scope, $http) {
$scope.email="";
$scope.password="";
$http({
method: "POST",
url: "http://localhost:3000/users/sign_in",
params: {email: $scope.email, password: $scope.password}
}).then(function mySuccess(response) {
// a string, or an object, carrying the response from the server.
$scope.myRes = response.data;
$scope.statuscode = response.status;
}, function myError(response) {
$scope.myRes = response.statusText;
});
});