Adding directive, the binding will not work

I'm new in Angular, I'm creating a mobile app with angularjs and ionic framework, i have an input (project name) in which i have a directive, to verify if the project name already exists, that directive will disable the data binding. Any help please.

 <input type="text" name="projectname" projectname-available    id="projectname" ng-minlength="3"
ng-maxlength="20" ng-pattern="projectPattern"  required   ng-model="form.projectname" >
<div class="error-container" ng-show="authorizationForm.projectname.$invalid && authorizationForm.projectname.$touched"  ng-messages="authorizationForm.projectname.$error"   ng-messages-include="templates/error-list.html">
            <div class="error" ng-message="required">
                <i class="ion-information-circled"></i>
                This field is invalid!
            </div>
            <div class="error" ng-if="authorizationForm.$error.projectnameExists" >
                <i class="ion-information-circled"></i>
                Project name exists already
            </div>

        </div>

this is the directive code

.directive('projectnameAvailable', function($timeout, $q,$cordovaSQLite) {
return {
 restrict: 'AE',
 require: 'ngModel',
 link: function(scope, elm, attr, model) {
   model.$asyncValidators.projectnameExists = function(projectName) {
     //here you should access the backend, to check if username exists
     //and return a promise
     query = "SELECT * FROM project WHERE name = ? ";
        $cordovaSQLite.execute(db, query, [projectName]).then(function(res1) {

            if(res1.rows.length>0) {
               exist = true;
               console.log('projet trouvé');
              }
            else
            {
            console.log('projet non trouvé');
             return exist = false;
             }
             }, function (err) {
                 console.error(JSON.stringify(err));
                }
             );
     var defer = $q.defer();
     $timeout(function(){
       model.$setValidity('projectnameExists', !exist);
       defer.resolve;
     }, 2000);
     return defer.promise;
   };
 }
}

});

Debug

 console.log('nom projet '+$scope.form.projectname );

i get nom projet undefined

plunker

You were nearly there. Here is a working plunk: http://plnkr.co/edit/qbAHG4dvDAHUOBzKbo5o?p=preview

I just changed one line in app.js from this:

defer.resolve;

to this:

defer.resolve(projectName);

Have fun.