SkyWalker
SkyWalker

Reputation: 14309

AngularJS: Are there multiple ways to apply ng-model to a form?

I'm using Scala-Play with the Play-Bootstrap extension and AngularJS. Since the controlling of the application is managed by AngularJS I need the form to be submitted and the response managed by AngularJS and not by the Play controller.

As I understand and using pure AngularJS one can use ng-model to link each input to a specific $scope nested variable e.g.

<form name="userForm">
    <label>
      Name:
      <input type="text" name="userName"
             ng-model="user.name"/>
    </label><br />
    <label>
      Other data:
      <input type="text" ng-model="user.data" />
    </label><br />
</form>

is it possible to accomplish the same by using ng-model on the form tag? instead of applying it to each input? the problem is that it is not possible injecting the needed ng-model to each input while using Play-Bootstrap i.e. this doesn't work:

@b3.text(computeInSampleForm("impliedVolSpread"), '_label -> messagesApi("myapp.impliedVolSpread"), 
         '_showConstraints -> false, 'ng-model -> "impliedVolSpread")

it fails with error value - is not a member of Symbol it would work if I only knew how to escape the - dash character.

Since I already created a customized version of the b3.form as b3.bgform it would be great if I could do bg-model at the form level ... is that possible?

Upvotes: 0

Views: 28

Answers (1)

Eric B
Eric B

Reputation: 4437

You can fix this error by explicitly converting to a Symbol:

Symbol("ng-model") -> "impliedVolSpread"

Or by using an implicit conversion import:

@import views.html.helper.Implicits._

Upvotes: 1

Related Questions