[英]Getting value of TextArea angularjs
I have a textarea: 我有一个文本区域:
<textarea class="notes" ng-model="notes" placeholder="Some text" style="height: 630px;"></textarea>
I then have a button: 然后,我有一个按钮:
<button ng-click="saveNotes(notes)"></button>
I then have this method in my controller: 然后,我在控制器中使用此方法:
$scope.saveNotes = function(notes) {
console.log(notes);
student.saveNotes(notes, function() {
console.log("Successfully saved notes.")
}
)};
From what I can tell, notes should return the value of the textarea yet it is consistently returning "undefined". 据我所知,注释应该返回textarea的值,但始终返回“未定义”。 Can anyone spot the problem?
谁能发现问题?
Thanks 谢谢
You retrieve notes' values in "$scope.notes". 您可以在“ $ scope.notes”中检索注释的值。 Solution:
解:
<button ng-click="saveNotes()"></button>
and: 和:
$scope.saveNotes = function() {
console.log($scope.notes);
student.saveNotes($scope.notes, function() {
console.log("Successfully saved notes.")
}
)};
Perhaps try assigning your variables to the controller rather then the scope like this 也许尝试将变量分配给控制器,而不是像这样的范围
<div ng-controller='myController as app'>
<textarea class="notes" ng-model="app.notes" placeholder="Some text" style="height: 630px;"></textarea>
<button ng-click="app.saveNotes(app.notes)"></button>
</div>
Then in your code under your controller 然后在您的控制器下的代码中
this.saveNotes = function(notes) {
console.log(notes);
student.saveNotes(notes, function() {
console.log("Successfully saved notes.")
}
)};
In my opinion it just helps prevent conflicting scopes 我认为这只是有助于防止范围冲突
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.