0
ng-repeat
의 텍스트 영역에 텍스트로 된 텍스트를 배열에 저장하고 있습니다. 내가 필요한 것은 Enter
을 눌러 새로운 텍스트 영역을 만들고 새로운 텍스트 영역에 새로운 텍스트 영역을 추가하지 않는 것입니다. 그래서 제가 가진 것은 이것과 같습니다.텍스트 영역 안의 ng-model 변수에서 newLine을 제거하십시오.
//Javascript
$scope.texts = [{}];
var addNewLine = function(index){
var newObj = {};
// NEXT LINE IS NOT WORKING
$scope.texts[index].text=$scope.texts[index].text.replace(/\n|\r|\r\n|\n\r/g, '');
$scope.texts.splice(index+1, 0, newObj);
$scope.selected = newObj;
}
var removeLine = function(index){
if(!$scope.texts[index].text||$scope.texts[index].length==0){
$scope.texts.splice(index, 1);
if(index==0) $scope.selected = $scope.texts[1];
else $scope.selected = $scope.texts[index-1];
}
}
$scope.checkPress = function(event, index){
if(event.keyCode == 13) addNewLine(index);
else if(event.keyCode == 8) removeLine(index);
}
//HTML
<textarea ng-repeat="textObj in texts"
ng-model="textObj.text" ng-keyup="checkPress($event, $index)"
focus-if="selected.$$hashKey == textObj.$$hashKey"
ng-click="selected=textObj"></textarea>
여기서 초점 - 내가 THIS PLUGIN을 사용하는 경우. 새 textarea
을 추가 할 때 이전 textarea
에서 newLine을 어떻게 제거 할 수 있습니까?
한 줄의 데이터 만 캡처하려는 경우 왜'input' 대신'textarea'를 사용합니까? 또한, 여기에 정말로 질문하지 않았습니다. 코드가 작동하지 않는 무언가가 있습니까? – Claies
textarea가 필요합니다. 컨테이너의 너비가 충분하지 않으면 입력이 두 줄을 내지 않습니다. 문제는 대체가 작동하지 않는 이유, 마지막 빈 줄을 제거하지 않는 이유입니다. –