加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angularjs – 带角型铸造的Scala.js

发布时间:2020-12-17 17:17:04 所属栏目:安全 来源:网络整理
导读:我正在尝试使用 Scala.JS和Angular实现一个应用程序,我在提交表单时遇到类型转换的问题. 我有以下代码: div ng-controller="usersCtrl"form novalidate class="simple-form" First Name: input type="text" ng-model="user.firstName" /br / Last Name: inp
我正在尝试使用 Scala.JS和Angular实现一个应用程序,我在提交表单时遇到类型转换的问题.

我有以下代码:

<div ng-controller="usersCtrl">
<form novalidate class="simple-form">
    First Name: <input type="text" ng-model="user.firstName" /><br />
    Last Name: <input type="text" ng-model="user.lastName" /><br />
    E-mail: <input type="email" ng-model="user.email" /><br />
    Password: <input type="password" ng-model="user.password" /><br />
    ConfirmPassword: <input type="password" ng-model="user.passwordConfirmation" /><br />
    <input type="submit" ng-click="controller.signup(user)" value="Save" />
</form>
@JSExport
@injectable("usersCtrl")
  class UsersCtrl(
  scope: UsersScope,proxy: UsersServiceProxy,val timeout: Timeout)
extends AbstractController[UsersScope](scope) {

  @JSExport
  def signup(user: UserSignup): Future[User] = {
    proxy.signup(scope.user)
  }
}


@JSExportAll
case class UserSignup(firstName: String,lastName: String,email: String,password: String,passwordConfirmation: String)

但是当我尝试提交表单时,我收到以下错误:

$c_sjsr_UndefinedBehaviorError {s$1: "An undefined behavior was detected: [object Object] is not an instance of rentalot.users.UserSignup",e$1: $c_jl_ClassCastException

我已经尝试了几个选项,包括通过作用域获取用户,将用户变量定义为UserSignup或UndefOf [UserSignup],但没有运气.当我尝试执行scope.user.toOption时后者失败.

有什么想法吗?

解决方法

Scala.JS无法自动将JS对象转换为Scala案例类.您需要定义一个外观.参见 this document.
它应该看起来像这样:

@js.native
trait UserSignup extends js.Object { 
  def firstName: String = js.native
  def lastName: String = js.native
  ...
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读