如何在AngularJS中使编辑按钮工作?

时间:2017-04-14 07:32:00

标签: angularjs

我是AngularJS的新手,我正在创建一个应用程序,我必须在其中编辑文本。我创建了按钮。但是,我需要一些帮助来设置编辑按钮。当用户点击编辑按钮时,我希望他们编辑文本。

  

这是我的编辑按钮

<a class="back" href="#/people">Back</a>

   <td><button class="btn btn-primary" ng-click="enableEditor()">Edit</button>
</td>

 <div class="people-view">
 <h2 class="name">{{people.name}}</h2>
 <span class="title">{{people.title}}</span>
 <span class="date">{{people.date}} </span>



  </div>

1 个答案:

答案 0 :(得分:3)

维护变量edit,您可以点击修改按钮true 取决于该变量切换文字输入

 <a class="back" href="#/lawyer">Back</a>

       <td><button class="btn btn-primary" ng-click="edit=ture">Edit</button>
    </td>

     <div class="people-view">
     <h2 class="name"><span ng-show="!edit">{{people.name}}</span><input ng-show="edit" value="{{people.name}}"></h2>
     <span class="title"><span ng-show="!edit">{{people.title}}<input ng-show="edit" value="{{people.title}}"></span></span>
     <span class="date"><span ng-show="!edit">{{people.date}} <input ng-show="edit" value="{{people.date}}"></span></span>



      </div>

Working demo