【问题标题】:TypeError: Cannot assign to read only property 'confirm_success_url'TypeError:无法分配给只读属性“confirm_success_url”
【发布时间】:2015-09-30 22:43:31
【问题描述】:

在所有浏览器中 EXCEPT 的 Angular 模块都存在问题,称为“ng-token-auth”。在 Rails 服务器上,我使用 gem “devise-token-auth”,它与 angular 模块无缝协作,创建 API 令牌认证框架。

我遇到的问题与$auth.SubmitRegistration() 方法有关。在我的 users_registration.coffee ngController 中发布在 github (https://github.com/lynndylanhurley/ng-token-auth#authsubmitregistration) 上的示例之后,我通过一个变量将表单数据(转换为 JSON)发送到 SubmitRegistration() 函数,然后该函数被发布到 rails(由 devise-token 处理-auth) 宝石。

但是,在发布任何数据之前提交表单时,立即会引发 javascript 错误,说明:TypeError: Cannot assign to read only property 'confirm_success_url' of

user_registrations.coffee(控制器):

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
 ])

form.html:

<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>

【问题讨论】:

    标签: javascript ruby-on-rails angularjs devise


    【解决方案1】:

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

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

    我没有意识到 confirm_success_url 是一个参数,它会与数据一起自动添加,因此在它不包含在其他参数中之前。

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

    【讨论】:

      猜你喜欢
      • 2019-12-06
      • 1970-01-01
      • 2017-03-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多