[英]Angular ng-model is undefined in JS
這是我的代碼
HTML:
<div class="someClass">
<label>Enter Text Here:</label>
<textarea id="content-editable" ng-model="myTextArea" ng-keyup="callme($event)">
</textarea>
</div>
JS:
var text = $scope.myTextArea.text
我在JS中遇到一個異常,“找不到未定義的屬性文本”。
我不確定是否需要text屬性來從textarea獲取文本,但是我在$scope.myTextArea
調試器中未定義
怎么了?
數據綁定需要的只是參考$scopel.myTextArea
,你不需要做.text
-見下面的演示:
angular.module("app", []).controller("ctrl", function($scope) { $scope.callme = function(event) { console.log($scope.myTextArea); } });
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> <div class="someClass" ng-app="app" ng-controller="ctrl"> <label>Enter Text Here:</label> <textarea id="content-editable" ng-model="myTextArea" ng-keyup="callme($event)"> </textarea> </div>
您不需要使用.text
cz,它將默認為您提供值。
只是這樣使用
var text = $scope.myTextArea;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.