【发布时间】:2016-07-12 21:19:08
【问题描述】:
我现在正在开发网站,ng-repeat 中有编辑注释字段功能。要编辑注释字段,用户需要先单击链接以显示表单,然后键入它,然后将其保存如下。问题是成功保存后我无法隐藏该输入。编码如下。
index.jade
tr(data-ng-repeat="application in job.applications")
td.notes
div.bold #{getMessage('Notes:')}
div.normal
div(ng-hide='showDetails')
{{application.note}}
.br
a.admin_edit_gray(href='#', ng-click="showDetails = ! showDetails") Edit Note
div(ng-show='showDetails')
textarea.form-control.small-text-font(ng-model='editableTitle', ng-show='showDetails', maxlength="100", ng-trim="false")
div.editable
div(ng-if="editableTitle.length == 100")
| #{getMessage('max 100 symbols.')}
a.small-text-editButton(href='#', ng-click='save(application, editableTitle, application.id)') Save
| |
a.small-text-cancelButton(href='#', ng-click="showDetails = ! showDetails") close
controller.js
$scope.showDetails = false;
$scope.noteFormData = {};
$scope.save = function(application, editableTitle, appId) {
$scope.noteFormData = {
appId: appId,
note: editableTitle
};
mytestService.writeNote($scope.noteFormData).then(
function (notemessage) {
application.note = notemessage;
alert('Note is successfully saved.');
$scope.showDetails = false;
}
);
};
成功保存后,我尝试将表单隐藏为$scope.showDetails = false;。但它根本不起作用。请帮我解决这个问题。
【问题讨论】:
-
尝试将
$scope.showDetails = false包装在$timeout中,这可能是一个摘要问题。 -
writeNote是否使用$http进行 AJAX 调用以将更新发布到您的服务器? -
@Arkantos 是的,当然。这是异步调用。
-
@Layoric 它在 $timeout 中不起作用。
标签: javascript jquery angularjs node.js