2016-07-02 5 views
0

에 부착 된 모델을 삭제 한 후 나는 newNoteText라는 $scope 변수에 부착 된 textarea있을 것이다. html로는 다음과 같습니다텍스트 영역이 명확하지 AngularJS와

<textarea spellcheck="true"    
      ng-model="newNoteText"></textarea> 

또한 입력 된 메모를 저장하는 버튼이있다.

 $scope.btnPost_clicked = function(newNoteText) { 
      $scope.addNote(newNoteText); 
      $scope.newNoteText = ''; 
     } 

내가 $ scope.newNoteText 빈 문자열로 재설정되고있는 CONSOLE.LOG을 통해 확인 :

<button type="button" class="btn btn-default" 
     ng-click="btnPost_clicked(newNoteText)">Post 
</button> 

다음은 컨트롤러 기능 btnPost_clicked입니다. 그러나 텍스트 영역에는 여전히 이전 텍스트가 들어 있습니다.

+0

... 텍스트 area'가 NG'내부에'않습니다 - 반복? –

+0

@ PankajParkar 아니요, 그것은 '반복 - 반복'에 없습니다. – Legion

+0

@Legion 더 많은 코드를 게시하면 도움이 될 수 있습니다. –

답변

0

당신이 $ scope.addNote (newNoteText)에서 오류가 발생하는 경우에만 발생할 수 있습니다. 아래 코드를보고 내가 만든 jsfiddle을 사용해보십시오. 난 그냥 addNote에 newNoteText를 로깅하고 모든게 잘 작동하는 것 같습니다.

HTML :

<div ng-controller="MainCtrl"> 

    <textarea spellcheck="true"    
      ng-model="newNoteText"></textarea> 

    <div>{{txt}}</div> 

    <button type="button" class="btn btn-default" 
     ng-click="btnPost_clicked(newNoteText)">Post 
</button> 
</div> 

자바 스크립트 :

var app = angular.module('myApp', []); 

app.controller('MainCtrl', ['$scope', function($scope) { 
    $scope.txt = ''; 

    $scope.btnPost_clicked = function(newNoteText) { 
    $scope.addNote(newNoteText); 
    $scope.newNoteText = ''; 
    }; 

    $scope.addNote = function(newNoteText) { 
    console.log(newNoteText); 
    } 
}]); 

jsfiddle : 나는 그 문제한다고 생각하지 않습니다 https://jsfiddle.net/nikdtu/d89ftrmg/

+0

'ng-if' 또는'ng-include'와 같은 하위 스코프 중첩이 일어날 수있는 유일한 이유는 아닙니다. – charlietfl

+0

그렇습니다.하지만이 경우에도 우리는 그렇게해서는 안됩니다. $ scope.btnPost_clicked를 호출 할 수 있습니까? –

+0

아니요 ...함수는 프리미티브가 아니기 때문에 자식 범위에서 상속이 있기 때문에 – charlietfl

관련 문제