繁体   English   中英

获取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.")
    }
)};

据我所知,注释应该返回textarea的值,但始终返回“未定义”。 谁能发现问题?

谢谢

您可以在“ $ 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.")
}
)};

我认为这只是有助于防止范围冲突

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM