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?

nycynik
  • 7,371
  • 8
  • 62
  • 87
Atomix
  • 2,440
  • 8
  • 36
  • 48

1 Answers1

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>

Hengjie
  • 4,598
  • 2
  • 30
  • 35