4

My HTML is as follows:

<textarea ng-model="cancelMessage"></textarea>
<span {{100 - cancelMessage.length}} characters remaining</span>

In my controller I declare a variable as follows:

$scope.cancelMessage = '';

When I type in the text area, the number of characters remaining actually updates. However, when I try to access

$scope.cancelMessage 

(via ng-click), the variable is still '' and not the text in the text area.

1
  • Could be a scope issue, can you include the HTML that includes the ng-click? Commented Jul 14, 2014 at 8:14

2 Answers 2

3

Had the same problem and this solved the problem for me:

Cannot get textarea value in angularjs

Basically Angular created a new scope. Use $parent.cancelMessage in your textarea ng-model attrbibute instead.

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

Comments

2

Created a fiddle for the problem. Hope you get an idea where you making the mistake.

Here is the controller function:

function test($scope){
    $scope.cancelMessage = '';
    $scope.clickTest = function(){
        alert($scope.cancelMessage);
    }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.