I created the actionButtons
directive:
function actionButtons(){
'use strict';
return {
scope: {},
restrict: 'AE',
bindToController: {
itemId: '@',
itemDescription: '@',
actionsText: '@',
previewAction: '&',
previewText: '@',
editAction: '&',
editText: '@',
removeAction: '&',
removeText: '@'
},
controller: ActionButtonsController,
controllerAs: 'actionButtonsCtrl',
templateUrl: 'src/views/directives/actionButtons.html'
};
}
The ActionButtonsController
controller associated with it is as follows:
/**
*
* @constructor
*/
function ActionButtonsController() {
'use strict';
var viewModel = this;
//not important assertions
}
/**
*
* @type {boolean}
*/
viewModel.hasItemDescription = typeof viewModel.itemDescription === 'string' &&
viewModel.itemDescription.length > 0;
/**
*
* @type {string}
*/
viewModel.previewText = viewModel.previewText || 'preview';
/**
*
* @type {string}
...
url-toggle aria-haspopup="true">
{{actionButtonsCtrl.actionsText}} <span class="sr-only" data-ng-if="::actionButtonsCtrl.hasItemDescription">
for {{::(actionButtonsCtrl.itemDescription)}}</span></button>
</div>
This is how I include it in my application:
<td class="col-md-3 col-xs-3 text-center">
<div data-action-buttons
data-item-id="{{author.id + '_' + author.name + '_' + author.surname}}"
data-item-description="{{author.name + ' ' + author.surname}}"
data-preview-action="authorCtrl.preview(author)"
data-edit-action="authorCtrl.edit(author)"
data-remove-action="authorCtrl.remove(author)"
></div>
</td>
However, I encountered some issues. For instance, although actionsText
and itemDescription
are both optional inputs, only actionsText
correctly defaults to "Actions" if not specified, while itemDescription
always remains visible in the HTML DOM even when not provided. Despite checking the controller code, the value of actionsText
appears as undefined at times, causing confusion. I am unsure why this happens and seek assistance in resolving this matter. Thank you for your help. P.S. I attempted to return the viewModel
variable from the controller without success. P.S. 2 Notably, specifying actionsText
directly (e.g.,
data-actions-text={{'Something'}}
) resolves the issue.