我有一个指令,在其中我点击一个字段,然后我可以编辑它。在这个指令中,我可以添加一个名为"typeinput“的属性。如果the = " textarea“,那么我希望动态字段是文本区域,而不是输入文本。我正在用ng-if做这个验证。

但是,如果我这样做,这将停止工作,并没有保存新的动态字段值。我怎么才能修好它?
<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>',发布于 2017-05-30 15:12:32
使用ngIf时,它会创建子作用域,因此在文本区域的ngModel和输入中,需要引用父作用域,如下所示:
ng-model="$parent.localModel"https://stackoverflow.com/questions/44265336
复制相似问题