title: How to call an application controller method from angular js directive
body: <p>Hi I want to make a validation directive. It basically will call a remote validation on the server. I would expect something like this:</p>
  
  <pre><code>&lt;input type="text" id="nome" required ng-model="client.context" available="checkAvailableContexts"&gt;
  </code></pre>
  
  <p>and that should call a method on my ClientController like this:</p>
  
  <pre><code>$scope.checkAvailableContexts = function(contexto, callbacks) {
      service.checkContextAvailability(contexto, callbacks);
  }
  </code></pre>
  
  <p>and this is my service method:</p>
  
  <pre><code>this.checkContextAvailability = function(context, externalCallbacks) {
   var url = angular.url("/clients/context/" + context + "/available"),
       callback = {
           success: function(){},
           error: function(){}
       };
  
   $.extend(callback, externalCallbacks)
   $.ajax({
       url: url,
       data: { context: context },
       success: function(data){
           $timeout(function(){
               callback.success(data); 
           },100);
       },
       type: "GET",
       dataType: "json",
       contentType: "application/json;charset=UTF-8onte"   
   });
  };
  </code></pre>
  
  <p>my directive is something like this:</p>
  
  <pre><code>.directive('available', function(){
    return {
        restrict: "A",
        require: "ngModel",
        replace: true,
        link: function(scope, element, attrs, controller){
            controller.$parsers.unshift(function (viewValue) {
                            //call the ClientsController method passing viewValue
                            //and callbacks that update the validity of the context
            })
        }
    }
  })
  </code></pre>
  
  <p>But I can't figure out how to call the clientController from inside the directive.</p>
  
  <p>I know I have attrs.available as the name of the function. But I can't execute it on the controller scope passing my parameters;</p>
  
  <p>Any help would be much appreciated!</p>