最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Replace input field with read only text in AngularJS - Stack Overflow

programmeradmin1浏览0评论

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.

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.

Share Improve this question asked Feb 4, 2013 at 16:00 OrganiccatOrganiccat 5,65118 gold badges60 silver badges106 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 9

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.

Try adding any of these functions in 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.

发布评论

评论列表(0)

  1. 暂无评论