유효한 지침 텍스트를 입력해야만 "저장"버튼을 비활성화하는 것이 가장 좋은 방법은 무엇입니까? "Save"버튼에서 ng-disable을 사용하려했지만 input 필드에 무엇인가 넣으면 활성화됩니다.입력 한 데이터가 데이터베이스에없는 경우 버튼을 비활성화하십시오.
HTML
<div class="row" ng-init="initUpsert()">
<div class="input-field col m4">
<label class="active" for="instructionText">Instruction Text</label>
<autocomplete
ng-if="!currentQuestion.id || currentQuestion.status === 'flagged'"
ng-model="currentQuestion.Instruction.instructionText"
data="instructionChoices"
attr-placeholder="Instruction Text"
attr-input-class="validate"
attr=id="instructionText"
on-type="getRemoteInstructions"
on-select="checkInstructionText"
autocomplete-required="true"></autocomplete>
<input ng-if="currentQuestion.id && currentQuestion.status !== 'flagged'" type="text" ng-model="currentQuestion.Instruction.instructionText" ng-disabled="true">
</div>
<button class="modal-action waves-effect btn waves-green teal white-text btn-flat" ng-click="spellcheck(true)" ng-show="currentQuestion.status === 'review' && isModified === true">
Save and Add Another
</button>
<button class="modal-action waves-effect btn waves-green teal white-text btn-flat" ng-click="spellcheck(false)" ng-show="currentQuestion.status === 'review' && isModified === true" ng-disable="invalidInstructionText">
Save
</button>
</div>
<ng-include src="'/views/modals/spellCheckModal.html'"></ng-include>
</div>
컨트롤러
$scope.checkInstructionText = function(instruction) {
$scope.validInstructionText = true;
$http.get("/api/instructions?searchInstructionText=" + instruction).then(function(response) {
if (instruction = response.data) {
window.alert ("You've selected a valid instruction text");
return $scope.validInstructionText = false;
}
else {
console.log("disable the save buttons");
return $scope.validInstructionText = true;
}
});
};
감사합니다. 내가 작동하도록했는데, $ scope.validInstructionText = true를 함수 외부로 옮긴 다음 ng-disable을 ng-disabled로 변경했습니다. – Jason