我試圖編輯一個字段,並在點擊按鈕時將標籤轉換爲文本字段並將其更改回按鍵事件(ng-keypress)上的標籤。使用控制器ng-show ng-hide
我正在通過控制器更改ng-show變量,但它不起作用。
HTML:
<div ng-app>
<div ng-controller="showCrtl">
<form>
<label ng-hide="editMode" >{{field}}</label>
<input ng-show="editMode" ng-keypress="changemode($event) " ng-model="field" >
<span class="pull-right" >
<button ng-click="editMode=true" class="btn-lg btn-warning" >edit </button> </span>
</form>
</div>
</div>
JS:
function showCrtl($scope){
$scope.field="Chanel";
$scope.changemode=function(event){
if(event.charCode==13){
$scope.editMode = false;
}
}
}
我的更新JS-小提琴鏈接:http://jsfiddle.net/8Yz7S/281/
然後,只要我開始輸入,它就會標記。 – Rachel
嘗試ng-blur – Sajeetharan
我想編輯字段,然後wehn我按回車它應該改回標籤 – Rachel