0

I have initial object and value in view not from controller.

<input type="text" data-ng-show="false" data-ng-init="crud.data.userId=1" data-ng-model="crud.data.userId">

<input type="text" data-ng-show="false" data-ng-init="crud.data.userParentId=2" data-ng-model="crud.data.userParentId">

And rest of form elements are visible for user to input.

<input type="text" data-ng-model="crud.data.userFamilyName">
<input type="text" data-ng-model="crud.data.userSpouseName">

I would like to reset those form elements in which i haven't initial value after submitting form.

I know it can be done by initializing it from controller but i have 100 of forms.

1 Answer 1

0

The data-ng-init works when the view is loaded (not restored from the cache) and sets up the object value. If you want to reinvoke the data-ng-init you have to reload it after the form submission. You can try to keep cache false and refresh the view. And this will leave all the input fields empty if they don't have initial value. And fill the value if they have.

Or you can simply reload the app (Not recommended).

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

4 Comments

I have to populate form in modal. How to implement in such case.
Sorry, I didn't get you : I have to populate form in modal. You can make a controller for a form. where you can initialize your form fields. And you can have a submit function which will submit the form to server and after success it will reset those scope variables like rud.data.userId=1, and others to null. It would be simple and manageable. I never make views such complicated using init function.
I there any option in which i can re-render view without reload.
I also tried re-rendering the view but it dint help. But you can try it by setting cache false and then refreshing the view. $state.go($state.current, {}, {reload: true});. May be it would help you.

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.