0

http://plnkr.co/edit/roJC9X

See the link above. I want to hide the textarea when the width of the text area is over 400px. How can this be done?

3
  • you mean, you want to hide the text area when the browser is wider then 400px? Commented Nov 28, 2012 at 22:23
  • no I want to hide the textarea when it is itself > 400px Commented Nov 28, 2012 at 22:31
  • so you need to listen for the resize event of the textarea? stackoverflow.com/questions/5570390/resize-event-for-textarea Commented Nov 28, 2012 at 22:40

1 Answer 1

2

As you're using Angular and you're dealing with view related code, you'd want to define a directive.

The code below is an example of what this directive would look like (written in CoffeeScript):

angular.module('yourAppName').directive('hideOnExceed', ->
  return {
    restrict: 'A', 
    link: (scope, element, attr) ->
      element.bind 'resize', ->
        if element.width() > 400
          element.hide()
        else
          element.show()
  }
)

Then simply define hideOnExceed as an attribute to the textarea tag:

<textarea ng-show="withinSize()" hideOnExceed>{{size}}</textarea>

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.