我正在尝试使用 angular.js 和 devise 设置登录。
这是我的表单 html:
<form ng-submit="submitLogin(loginForm)" role="form" ng-init="loginForm = {}">
<div class="form-group">
<label for="email">Email</label>
<input type="email" name="email" id="email" ng-model="loginForm.email" required="required" class="form-control"> </div>
<div class="form-group">
<label for="password">Password</label>
<input type="password" name="password" id="password" ng-model="loginForm.password" required="required" class="form-control"> </div>
<button type="submit" class="btn btn-primary btn-lg">Sign in</button>
</form>
所以基本上我的表单总是POST
-ing到/api/auth/sign_in
。但是我的 api 路径中也有一个版本。
因此 /api/v1/auth/sign_in
可以工作,但 /api/auth/sign_in
不行。
如何更改表单操作以包含 api 版本?
更新,这是重要的 Angular 相关信息
angular
.module('AngularRails', [
'ngAnimate',
'ngCookies',
'ngResource',
'ngRoute',
'ngSanitize',
'ngTouch',
'templates',
'ng-token-auth'
]).config(function ($routeProvider, $locationProvider) {
$routeProvider
.when('/app/sign_in', {
templateUrl: 'user_sessions/new.html',
controller: 'UserSessionsCtrl'
})
.otherwise({
redirectTo: '/'
});
$locationProvider.html5Mode({
enabled: true,
requireBase: false
});
});
并且 submitLogin
来自 here 。有没有办法配置或重写 ng-token-auth (基于 angular.js 的 token 的身份验证模块)的函数 submitLogin
?
最佳答案
你可以做类似的事情
$scope.actionUrl = $scope.ContextUrl + '/api/v1/auth/sign_in';
$scope.ContextUrl 可能是您想要提供的使 url 可达的任何内容。
或者
<form action="{{ ContextUrl + '/api/v1/auth/sign_in' }}">
这是一个肮脏的答案,尝试一下并让我知道。
关于javascript - 形成 Angular Action ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27737324/