1

This is my code

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

I am getting an exception in JS that "cannot find property text of undefined".

I am not sure if text property is needed to get the text from textarea but I am getting undefined in debugger for $scope.myTextArea

Whats wrong?

1
  • have you assigned $scope.myTextArea = { text : 'abc' } in your controller somewhere ? Commented Dec 21, 2016 at 2:15

2 Answers 2

2

Data binding require just to refer $scopel.myTextArea and you don't need to do .text - see demo below:

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>

Sign up to request clarification or add additional context in comments.

Comments

1

You don't need to use .text cz it'll by default give you the value.

just use like this

var text = $scope.myTextArea;

Comments