1

I am using ng-model to link input values with model.

If I set default value in input box it does not show in $scope, but If I change anything in this input I can see changes.

<input type='text' id="save_quote_email" name="save_quote_email" ng-model="AutoQuote.postAutoQuoteObj.ApplicationInfo.GeneralPartyInfo.ContactInfo.Emails[0].EmailAddress" value="[email protected]" />
{{AutoQuote.postAutoQuoteObj.ApplicationInfo.GeneralPartyInfo.ContactInfo.Emails[0].EmailAddress}}

I can set this value in controller, then it will work, but such values will come in form when my html loaded.

1
  • using ng-init should work Commented Jul 15, 2016 at 4:58

3 Answers 3

1

First, you shouldn't use ng-init in this case.

From docs:

This directive can be abused to add unnecessary amounts of logic into your templates. There are only a few appropriate uses of ngInit, such as for aliasing special properties of ngRepeat, as seen in the demo below; and for injecting data via server side scripting. Besides these few cases, you should use controllers rather than ngInit to initialize values on a scope.

Then, simply do it in your controller:

AutoQuote.postAutoQuoteObj.ApplicationInfo.GeneralPartyInfo.ContactInfo.Emails[0].EmailAddress = "[email protected]";
Sign up to request clarification or add additional context in comments.

1 Comment

I am trying to get input value using document.getElementById("save_quote_email"); in function dtoresource.rc1Step1DTO, but not getting any value.
0

Add

 ng-init="AutoQuote.postAutoQuoteObj.ApplicationInfo.GeneralPartyInfo.ContactInfo.Emails[0].EmailAddress='[email protected]'"

Comments

0
ng-init="AutoQuote.postAutoQuoteObj.ApplicationInfo.GeneralPartyInfo.ContactInfo.Emails[0].EmailAddress='[email protected]'"

1 Comment

how is this different from the answer above? you edited your answer altogether!

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.