Replace input field with read-only text in AngularJS

I have some jQuery currently set up to remove the input field from the view and write the input field value as plain text within a range, however I am wondering how AngularJS handles this. The event happens when the form is submitted, this part is already done via ajax. Not only is it one input, but they are all on a form so you can see the results of what you just submitted.

+3


source to share


2 answers


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

When you submit the form, switch 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. Set to false in your submit function.

+9


source


Try adding any of these functions to the html where you call the .js function

 <script>
    $(function() {

 $('#fieldName').attr("readonly","readonly");

 });
</script>

      

OR



     <script>
    $(function() {

 $('#fieldName').attr("readonly", true);

 });
</script>

      

Where #fieldName

is the ID of the input field.

-1


source







All Articles