I was using AngularJs-1.0.7 and Bootstrap in my application. Recently I migrated from AngularJs-1.0.7 to AngularJs-1.2. I am using Bootstrap\'s Accordions and Tabs.
Your solution in your question does work, but to prevent having to check for each anchor's id, change
if (attrs.href === '#firstTab'|| attrs.href === '#secondTab')
to
if (attrs.href && attrs.href.indexOf('#') > -1)
Directive:
.directive('a', function () {
return {
restrict: 'E',
link: function (scope, elem, attrs) {
if (attrs.href && attrs.href.indexOf('#') > -1) {
elem.on('click', function (e) {
e.preventDefault();
});
}
}
};
})