angularjs – 带角型铸造的Scala.js

前端之家收集整理的这篇文章主要介绍了angularjs – 带角型铸造的Scala.js前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在尝试使用 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
  ...
}

猜你在找的Angularjs相关文章