AngularJS:有多种方法可以将ng-model应用于表单吗?(AngularJS: Are there multiple ways to apply ng-model to a form?)

我正在使用Scala-Play和Play-Bootstrap扩展和AngularJS。 由于应用程序的控制由AngularJS管理,我需要提交表单并由AngularJS管理响应,而不是由Play控制器管理。

据我所知并使用纯AngularJS,可以使用ng-model将每个输入链接到特定的$scope嵌套变量,例如

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

是否可以通过在form标签上使用ng-model来完成相同的操作? 而不是将它应用于每个输入? 问题是在使用Play-Bootstrap时不可能为每个输入注入所需的ng-model ,即这不起作用:

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

它失败并带有错误value - is not a member of Symbol如果我只知道如何逃避 - 破折号字符value - is not a member of Symbol它value - is not a member of Symbol 。

由于我已经创建了b3.form的自定义版本作为b3.bgform ,如果我可以在表单级别执行bg-model ,那将是很好的...这可能吗?

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?

最满意答案

您可以通过显式转换为符号来修复此错误:

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

或者使用隐式转换导入:

@import views.html.helper.Implicits._

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

更多推荐