Scala.js with type angular

I am trying to implement an application with Scala.JS and Angular, and before submitting the form I had a problem with the casting type.

I have the following code:

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

But when I try to submit the form, I get the following error:

$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

I tried several options, including getting the user through the area, with a user variable defined either as UserSignup or UndefOf [UserSignup], but with no luck. The latter does not work when I try to do scope.user.toOption.

Any thoughts?

+4
source share
1 answer

Scala.JS JS Scala. . . . :

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

Source: https://habr.com/ru/post/1652149/


All Articles