Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
在将 AngularJS 与 rails 应用程序一起使用时,我在编辑记录时遇到了问题,文本字段的值设置为空白。有没有办法告诉 AngularJS 使用 rails 给表单元素的值作为初始值?
我整理了一个 JSFiddle 来演示我遇到的问题:
http://jsfiddle.net/YUza7/15/
使用 ng-init 指令,因为它在运行任何代码之前加载初始值。
http://jsfiddle.net/YUza7/17/
正如您在回答中已经说明的那样,您可以使用 ng-init。
一种更“有角度的方式”是修改您的 $scope/data 模型,而不是在表单元素上使用 value 参数。
另请参阅AngularJS - 使用 ng-model 时忽略输入文本框上的值属性?