我有一个textarea
附加到名为$scope
的{{1}}变量。 html是:
newNoteText
还有一个保存键入的音符的按钮。
<textarea spellcheck="true"
ng-model="newNoteText"></textarea>
这里是控制器功能<button type="button" class="btn btn-default"
ng-click="btnPost_clicked(newNoteText)">Post
</button>
:
btnPost_clicked
我通过console.log确认$ scope.newNoteText正在重置为空字符串。但是textarea仍然保留着旧文本。
答案 0 :(得分: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>
JavaScript:
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);
}
}]);