I have a buch of movies, think Netflix. Each movie have a number of tags assigned to it: Comedy, Horror etc.
When I click on a tag the view is filtered accordingly, that works great. But what I also wish to do is to add a class to all the tags, with the same name (on every other movie), as the one clicked.
I could do an ugly jQuery :contains in the click-event, but that doesn't feel right.
I'm a AJS noob, but I'm sure there's a better AJS way of achieving this?
(function () {
var directive = function () {
return {
restrict: 'A',
template: '<li data-ng-repeat = "tag in movie.genre">{{tag}}</li>',
link : function ($scope, element, attrs) {
element.bind('click', function (e) {
var linkText = e.target.innerText;
if ($scope.$parent.category === linkText) {
return;
}
$scope.$parent.category = linkText;
$scope.$apply();
})
}
};
};
angular.module('videoApp')
.directive('videoTags', directive);
}());