The directive in question is this guy here: Dynamic template in directive based on attributes?
Anyway, here's what I'm trying to accomplish.
This <titlebar>
directive can take an attribute called edit-button
. If this exists, and when the button is clicked, I'd like to set a $scope variable in my controllers that will toggle the visibility of buttons to delete/edit an item.
For example, if I set $scope.currentlyEditting = true;
in my directive, I'd tie this to the controller, and then use ng-show
to show/hide the controls. I'm just not sure how to get that data into my controller.
titleBar directive:
robus.directive("titlebar", function() {
return {
restrict: "E",
template: "<header class='bar-title' ng-class='{\"sub-view\": view}'>"+
"<a class='button' ng-click='goBack()' ng-show='back'><i class='icon-arrow-left'></i> Back</a>" +
"<h1 class='title' ng-transclude>" +
"<span class='sub-title' ng-show='view'>{{view}}</span></h1>" +
"<a class='button' ng-click='showEdit()' ng-show='edit'>Edit</a>" +
"</header>",
scope: {
view: '@view',
edit: '@editButton',
back: '@backButton'
},
transclude: true,
replace: true,
link: function ($scope, $element, attrs, ctrl) {
// $scope.$apply();
},
controller: function($scope, $element, $attrs, $location, $routeParams) {
/* simple back button implementation */
$scope.goBack = function() {
history.back(-1)
}
// $scope.showEdit = function() {
// $scope.currentlyEditting = true;
// }
}
}
});