0

There is HTML code:

<div class="item" data-url="link"></div>
<div class="item" data-url="link"></div>
<div class="item" data-url="link"></div>

In Jquery I can do:

$('.item').click(function () {
   var url = $(this).attr('data-url');
   redirect(url);
});

How do this in Angular?

2 Answers 2

1

If for some reason you don't want to wrap your <div>s in an <a>, you can just add an ng-click attribute to them and redirect in your controller code. If your redirect is internal, you should look into using the $location service, otherwise use the $window service.

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

1 Comment

@sahe: once you are done with writing a method in your controller you can move the code to a directive something like this stackoverflow.com/a/22592535/537079
0

Try this i just create an example. you can modify as per your requirement. Then want to configure the $locationservice in your controller.

//i just create an example you can modify as your requirement
$scope.redirect = function(){    
       $location.path("/route");
}
<div ng-app="myApp" ng-controller="myCtrl">
<div class="item" data-url="link" ng-click='redirect()'>redirect</div>
</div>

Comments

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.