1

When using AngularJS with a rails application I've hit a problem when editing records the value of the text fields is set to blank. Is there a way to tell AngularJS to use the values rails gives the form elements as the initial value?

I've put together a JSFiddle to demonstrate the issue I'm having:

http://jsfiddle.net/YUza7/15/

map7
  • 5,096
  • 6
  • 65
  • 128

2 Answers2

5

Used ng-init directive as it loads initial values before running any of your code.

http://jsfiddle.net/YUza7/17/

map7
  • 5,096
  • 6
  • 65
  • 128
2

As you already stated in your answer, you can use ng-init.

A more "Angular way" of doing it would be to modify your $scope/data model and not use the value parameter on your form elements.

See also AngularJS - Value attribute on an input text box is ignored when there is a ng-model used?

Community
  • 1
  • 1
Mark Rajcok
  • 362,217
  • 114
  • 495
  • 492
  • Are you saying my rails controller should return 'json' instead of rendering the html template? – map7 Oct 04 '12 at 00:15
  • 1
    If your rails controller is only rendering the HTML template (and not the AngularJS controller code too, which is where I was hoping you could initialize your $scope properties), then ng-init is the only approach. – Mark Rajcok Oct 04 '12 at 02:47