2014-08-31 15 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