javascript - Angular.js 与 Ruby On Rails Forms 的集成

标签 javascript html ruby-on-rails forms angularjs

使用 angular.js 通常像 ng-click 或 ng-model 这样的项目直接写在 html 表单元素中,就像这样....

<input type="text" ng-model="name">

我如何使用 Rails 做到这一点?由于 rails 使用嵌入式 ruby​​ 并生成 html....

<%= form_for(@user) do |f| %>
<%= f.label :name %>
<%= f.text_field :name %>

如何将 ng-model 添加到 <%= f.text_field :name %> ?

最佳答案

理想情况下,您不希望混合使用嵌入式 ruby​​ 插值和 Angular 的插值。最好让 ruby​​ 异步地将 JSON 提供给 Angular,并让 Angular 负责在客户端填充数据。

关于javascript - Angular.js 与 Ruby On Rails Forms 的集成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11106631/

相关文章:

ruby-on-rails - 何时在登录过程的 BDD 周期中从 Cucumber 切换到 rspec

ruby-on-rails - rails jbuilder : how to build a JSON from an array with the key equals to the array values

ruby-on-rails - Rails 3.1 中 API 链接的最佳放置位置是哪里

javascript - jquery 接收文本区域中输入的文本并将其传递给后端处理程序(perl、php 等)

javascript - 非 ES6 让替代方案

javascript - 使用命名空间对象的未定义 var 不会引发错误

javascript - ECMAScript 规范中的 `ExpressionNoIn` 是什么意思?

css - 如何用纯CSS显示div后面的内容?

html - 将多个 html 模板组合成单个 index.html 文件

javascript - 如何从汉字生成 url slug?