1

I'm a newbie to angular, and I'm playing around with it to try and understand how things work. I have an href as part of the template of a directive and an action associated with clicking the link. I would like to know how I can change the action when the user clicks on the link. I tried using a link function in my template, but I couldn't even get it to fire a message to the console.

Here is my link function:

var linkFunction = function(scope) {
    scope.$watch(scope.loggedin, function() {
        console.log('Here');
      });
  };

Any pointers? Or is there a better way. TIA

1 Answer 1

2

Link function is part of directive. You can use an ng-click directive in the anchor tag in the template and provide its implementation in the linking function of the directive.

//template
<a href="" ng-click="doThis()">Click Me </a>

//Link function in directive
function(scope) {
    scope.doThis = function() {
        console.log("doing this);
    }
}
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, that was a lot easier than I thought.

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.