title: angular js: Unable to validate a textarea
body: <p>fellas!</p>
  
  <p>I'm trying to validate a text area upon clicking a link. Thing is, It's not coming inside a form. And when a user clicks a link, content entered in the text area should be posted (saved to database). </p>
  
  <p>I wrote a validation for that. And unfortunately, it's not working and I'm able to make blank posts. I'm trying to prevent blank post posting. I have recreated the form and the controller in a fiddle. Link I'll provide down. but before that, take a look at my html and js code.</p>
  
  <p><strong>HTML</strong></p>
  
  <pre><code>&lt;div ng-app="myApp" ng-controller="myMap"&gt;
    &lt;div class="post-textarea" ng-class="{ 'has-error': vm.currentPost.content.$dirty &amp;&amp; vm.currentPost.content.$error.required }"&gt;
      &lt;textarea class="form-control" rows="3" ng-model="vm.currentPost.content" required&gt;&lt;/textarea&gt;
      &lt;a ng-click="vm.addPost(vm.currentPost.content,vm.currentPost.$valid)"&gt;Clik to Post and validate&lt;/a&gt;
    &lt;/div&gt;
  &lt;/div&gt;
  
  JavaScript
  
  angular.module('myApp', [])
    .factory('myService', function($http) {
      var baseUrl = 'api/';
      return {
        postCurrentPost: function(newPost) {
          var dataPost = {
            newPost: newPost
          };
          return $http({
            method: 'post',
            url: baseUrl + 'postCurrentPost',
            data: dataPost,
            headers: {
              'Content-Type': 'application/x-www-form-urlencoded'
            }
          });
        }
      };
  
    })
    .controller('myMap', function(myService, $http, $scope) {
  
      var vm = this;
      var userObject;
  
      // Add a post
      vm.addPost = function(newPost, isValid) {
        if (isValid) {
          var currentPost = vm.currentPost;
          currentPost.content = ""; //clear post textarea
          myService.postCurrentPost(newPost).success(function(data) {
            vm.posts = data;
          });
        } else {
          alert('Validation not working');
        }
      };
      //Check validation
      $scope.getError = function(error, name) {
        if (angular.isDefined(error)) {
          if (error.required &amp;&amp; name == 'vm.currentPost.content') {
            return "This field is required";
          }
        }
      }
    });
  </code></pre>
  
  <p>And here's a <a href="https://jsfiddle.net/iamsajeev/8v6mt2fy/" rel="nofollow">FIDDLE</a>.</p>