Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Replace input field with read only text in AngularJS

I have some jQuery currently set up to remove the input field from view and write the value of the input field as plain text inside a span, however I'm wondering how AngularJS would handle this. The event happens upon submitting a form, that part is already done through ajax as well. It's not just one input, it's all of them on the form so you can see the results of what you just submitted.

like image 384
Organiccat Avatar asked Feb 23 '26 18:02

Organiccat


1 Answers

Use ng-show and/or ng-hide on each input field and its associated text equivalent.

When you submit the form, toggle some $scope property:

<input type="text" ... ng-model='text1' ng-show="editMode">
<span ng-hide="editMode">{{text1}}</span>

In your controller, initialize editMode to true. In your submit function, set it to false.

like image 130
Mark Rajcok Avatar answered Feb 26 '26 08:02

Mark Rajcok