TypeError:无法分配给只读属性'confirm_success_url'

时间:2015-09-30 22:43:32

标签: javascript ruby-on-rails angularjs devise

在Firefox的所有浏览器 EXCEPT 中出现角度模块问题,称为“ng-token-auth”。在rails服务器上,我使用gem“devise-token-auth”,它与angular模块无缝地工作,以创建一个API令牌认证框架。

我遇到的问题是使用TypeError: Cannot assign to read only property 'confirm_success_url' of方法。在我的users_registration.coffee ngController中的github(https://github.com/lynndylanhurley/ng-token-auth#authsubmitregistration)上发布的示例之后,我通过变量将表单数据(转换为JSON)发送到SubmitRegistration()函数,然后将其发布到rails(由设计处理) -token-auth)gem。

然而,在发布任何数据之前,在表单提交时立即会引发javascript错误:angular.module('Authentication').controller('UserRegistrationsController',['$scope', '$rootScope','$auth','$state', ($scope, $rootScope, $auth, $state) -> $scope.handleRegBtnClick = -> r = $rootScope.availability f = $scope.registrationForm parameter = JSON.stringify( zone_id: r.zone.id first_name: f.first_name last_name: f.last_name email: f.email password: f.password) $auth.submitRegistration(parameter).then -> $auth.submitLogin email: $scope.registrationForm.email password: $scope.registrationForm.password ])

user_registrations.coffee(controller):

<form ng-submit="handleRegBtnClick()" role="form" ng-init="registrationForm =  {}">
<div class="form-group">
<label for="first_name">First Name</label>
<input type="first_name"
       name="first_name"
       id="first_name"
       ng-model="registrationForm.first_name"
       required="required"
       class="form-control">
</div>
........
 <div class="form-group">
<label for="email">Email</label>
<input type="email"
       name="email"
       id="email"
       ng-model="registrationForm.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="registrationForm.password"
       required="required"
       class="form-control">
</div>

<button type="submit" class="btn btn-primary btn-lg">Register</button>
</form>

form.html:

if (!(edtvUsername.equals(" ") && (edtvPassword.equals(" ")))) 

1 个答案:

答案 0 :(得分:0)

所以我最终解决了这个问题。问题来自于使用JSON.stringify,而我需要使用angular.extend

parameter = angular.extend(
zone_id: r.zone_id
.....

我没有意识到,但是confirm_success_url是一个自动添加的参数,因此在它没有被其他参数包含之前就已经添加了。

无论如何,它现在适用于所有浏览器。

相关问题