Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AngularJS Ionic Directive don't work

I'm using AngularJS and Ionic in a project, and I wanted to try creating directives.It doesn't shows up any error or warning message, but it also does not executes the directive's function. Right now, my code is pretty much this, Here is the js file:

angular.module('wingz').directives('preventSubmit',function(){
return {
    restrict: 'A',
    link: function(scope,element,attr){
        console.log('in directive');
        element.bind('submit',function(e){
            if(!element.$valid){
                e.preventDefault();
                console.log(element.child);
            }
        });
    }
}

});

and here is the html:

<form name="form" class="credit-card-form" prevent-submit ng-submit="doAddCard()">

It's already loaded in the index.html file and I haven't use the scope déclaration in it because I want to use the parent scope. Is anybody already had a problem like that I'll be glad to hear about because this is driving me crazy ...

Thanks a lot

like image 387
Benjamin Roullet Avatar asked Sep 01 '26 17:09

Benjamin Roullet


1 Answers

it should be angular.module('wingz').directive('preventSubmit', function() { ... }) not .directives

like image 185
tmaximini Avatar answered Sep 04 '26 03:09

tmaximini