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/

2 Answers 2

5

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

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

Sign up to request clarification or add additional context in comments.

Comments

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?

2 Comments

Are you saying my rails controller should return 'json' instead of rendering the html template?
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.