我有一個指令,我點擊一個字段然後編輯它。對於這個指令,我可以添加一個名爲「typeinput」的屬性。如果typeinput =「textarea」,那麼我想動態字段是一個textarea而不是輸入文本。我在ng-if的幫助下做了這個驗證。動態修改文本字段。 Angular.js
但如果我這樣做這個停止工作,並在新的動態字段值不會被保存。我該如何解決它?
<div ng-repeat="faq in faqs">
<a href='' click-to-edit ng-model='faq.pregunta' typeinput='textarea' >{{faq.pregunta}}</a>
</div>
.directive('clickToEdit', function($timeout,$compile) {
return {
require: 'ngModel',
scope: {
model: '=ngModel'
},
replace: true,
transclude: false,
// includes our template
template:
'<div class="templateRoot">'+
'<div class="hover-edit-trigger" title="click to edit">'+
'<div class="hover-text-field" ng-show="!editState" ng-click="toggle()">{{model}}</div>'+
//'<span ng-if="type==true">'+
'<input class="inputText" type="text" ng-model="localModel" ng-enter="save()" ng-show="editState" />' +
//'</span>'+
//'<span ng-if="type==false">'+
//'<textarea class="inputText" ng-model="localModel" ng-enter="save()" ng-show="editState" />' +
//'</span>'+
'<div class="edit-button-group pull-right" ng-show="editState">'+
'<div class="glyphicon glyphicon-ok" ng-click="save()"></div>'+
'<div class="glyphicon glyphicon-remove" ng-click="cancel()"></div>'+
'</div>'+
'</div>'+
'</div>',
https://jsfiddle.net/ybmrzo5w/
你plunker鏈路斷開時 – JeanJacques
plunker不迴應...等我更新鏈接.. – yavg
@JeanJacques https://jsfiddle.net/ybmrzo5w/ – yavg