获取 TextArea 的值 angularjs
Getting value of TextArea angularjs
我有一个文本区域:
<textarea class="notes" ng-model="notes" placeholder="Some text" style="height: 630px;"></textarea>
然后我有一个按钮:
<button ng-click="saveNotes(notes)"></button>
然后我的控制器中有这个方法:
$scope.saveNotes = function(notes) {
console.log(notes);
student.saveNotes(notes, function() {
console.log("Successfully saved notes.")
}
)};
据我所知,注释应该 return textarea 的值,但它始终 returning "undefined"。谁能发现问题?
谢谢
您在“$scope.notes”中检索了注释值。
解决方案:
<button ng-click="saveNotes()"></button>
和:
$scope.saveNotes = function() {
console.log($scope.notes);
student.saveNotes($scope.notes, function() {
console.log("Successfully saved notes.")
}
)};
也许尝试将变量分配给控制器而不是像这样的范围
<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>
然后在你控制器下的代码中
this.saveNotes = function(notes) {
console.log(notes);
student.saveNotes(notes, function() {
console.log("Successfully saved notes.")
}
)};
在我看来,它只是有助于防止范围冲突
我有一个文本区域:
<textarea class="notes" ng-model="notes" placeholder="Some text" style="height: 630px;"></textarea>
然后我有一个按钮:
<button ng-click="saveNotes(notes)"></button>
然后我的控制器中有这个方法:
$scope.saveNotes = function(notes) {
console.log(notes);
student.saveNotes(notes, function() {
console.log("Successfully saved notes.")
}
)};
据我所知,注释应该 return textarea 的值,但它始终 returning "undefined"。谁能发现问题?
谢谢
您在“$scope.notes”中检索了注释值。 解决方案:
<button ng-click="saveNotes()"></button>
和:
$scope.saveNotes = function() {
console.log($scope.notes);
student.saveNotes($scope.notes, function() {
console.log("Successfully saved notes.")
}
)};
也许尝试将变量分配给控制器而不是像这样的范围
<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>
然后在你控制器下的代码中
this.saveNotes = function(notes) {
console.log(notes);
student.saveNotes(notes, function() {
console.log("Successfully saved notes.")
}
)};
在我看来,它只是有助于防止范围冲突