A specialized directive has been crafted below, designed to generate a series of buttons relying on the data supplied to it.
angular.module('btnbar.directive', ['messaging']).
directive("btnBar", function(){
return {
restrict: 'E',
$scope.buttons = [{href: '#/students', icon:'icon-ok'},
{href: '#/students', icon:'icon-remove'},
{href: '#/students/new', icon:'icon-plus'}];
},
template:'<div class="btn-toolbar">' +
'<a class="btn" ng-repeat="b in buttons" href={{b.href}}>' +
'<i class={{b.icon}}></i></a></div>',
replace:true
}
});
The aforementioned directive functions effectively. It is desired that whenever the ng-view within the view shifts, a fresh array should be passed for the buttons.
Hence, two specific tasks need to be addressed -
Detect any alteration in the route.
Upon a change in the route, update the 'buttons' variable within the scope of 'btnbar.directive'.
Is there an optimal way to carry out these actions?