0
在這裏,我從服務器端獲取錯誤消息,稱爲「重複標題」在身體本身。但我的問題是,在這個例子中,標題長度應該是24個字符。但是,如果標題存在,那麼它會顯示一條錯誤消息。我可以如何解決與角js中的重複標題?
,但我的要求是什麼,如果是重複的標題,我們進入下一個字母重複的消息將需要消失了之後
這裏是該代碼...
<div class="col-md-12">
<form name="taskForm" class="form-horizontal" ng-submit="create()">
<div class="form-group">
<div class="col-xs-10 col-md-11">
<input name="title" type="text" class="form-control place" ng-model="title" id="title" placeholder="Enter Task Timer Here">
<span ng-show="duplicateTitle" class="text-danger">Duplicate Task Title. Please choose Unique Title!</span>
</div>
<div class="col-xs-1">
<span ng-click="create()" class="glyphicon glyphicon-plus plusIcon"></span>
</div>
</div>
</form>
</div>
控制器文件...
$scope.create = function() {
var currentDate = new Date();
for (var i = 0; i < $scope.tasks.length; i++) {
if ($scope.tasks[i].title === this.title) {
$scope.duplicateTitle = true;
console.log("duplictae" + $scope.duplicateTitle);
return;
}
}
var task = new Tasks({
'title': this.title,
'description': this.description,
'duration': 0,
// 'lastStart': currentDate
});
task.$save(function (response) {
//$location.path('tasks');
$scope.duplicateTitle = false;
//$scope.tasks.push(response);
$scope.tasks = Tasks.query();
$scope.title = '';
$scope.description = '';
}, function (errorResponse) {
$scope.error = errorResponse.data.message;
});
};