简体   繁体   中英

Angular Reset Initialization Value which is in view not in controller

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.

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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM