0

I am very new to creating AngularJs directive , so below i have created directive and when user click on delete button i am checking what are the values of scope,element and attrs but its not printing anything in console. ProcessDTO is the json data in the controller.

Any idea what i am missing here, i have read the directive documentation but if someone can put some light and explain it as beginner level it would be great.

html

<button class="btn btn-danger"
        type="button" autodelete delete-tags="processDTO">Delete</button>

directive.js

angular.module('App').directive('autoDelete', function () {
    'use strict';
    return{
      restrict:'A',
      scope:{
      autoDeleteTags: '=deleteTags'
      },
      link:function(scope,element,attr){
        $(element).click(function(){
          console.log('Element',element);
          console.log('SCOPE',scope);
          console.log('ATTRS',attr);
        })
      }
  }

});

1 Answer 1

2

The directive named autoDelete is looking for attribute auto-delete not autodelete

Try:

<button class="btn btn-danger"
        type="button" auto-delete delete-tags="processDTO">Delete</button>

Also would suggest using ng-click instead of creating your own event handlers

Sign up to request clarification or add additional context in comments.

4 Comments

Thanks that resolve the problem , but for attr it should print json object correct ? I dont see the object from controller.
Not really clear what you are asking. attr.deleteTags would be string == "processDTO"
may be i should ask if i have processDTO object in controller how can i access that in directive i thought we are accessing through attr.deleteTags.
Great i can see that printing scope.autoDeleteTags, Thank you

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.