2014-08-31 66 views
2

我有一个导轨形式,看起来像这样:如何把在轨angularjs属性ERB

<%= form_for(resource, as: resource_name, url: registration_path(resource_name), html: { method: :put }) do |f| %> 
    <%= devise_error_messages! %> 


    <div><%= f.label :email %><br /> 
    <%= f.text_field :email %></div> 


    <div><%= f.label :password %><br /> 
    <%= f.text_field :password %></div> 

    <div><%= f.label :current_password %> <i>(we need your current password to confirm your changes)</i><br /> 
    <%= f.password_field :current_password, autocomplete: "off" %></div> 


    <div><%= f.submit "Update" %></div> 
<% end %> 

不过,我想的电子邮件文本字段绑定在某个AngularJS模式,使价值电子邮件表格输入始终与$scope变量绑定。在纯HTML,它应该是这样的:

<input name="email" ng-model="myValue"></input> 

但是因为它ERB,而不是普通的HTML,我不知道如何角数据绑定到它。

如何在rails中将ng-model属性连接到erb格式?

回答

4

你应该通过角属性中输入的数据属性,像这样:

<%= f.text_field :email, data: { 'ng-model' => 'myValue' } %> 

这将与data-添加前缀角属性。

+0

嗨钢轨怎么样? – wiwit 2016-11-17 06:34:12

+0

相同的交易。只需使用'ng-repeat'而不是'ng-model' – Jon 2016-11-17 07:00:49