I am storing a load of button shortcut types in an array of objects. I am trying to write a directive that will return some values depending on the name of the object. Here is my array stored within the controller:
angular.module('app')
.controller('BtnCtrl', function ($scope) {
//......rest of controller code here
$scope.hotKeys = [
{name: 'primaryTest', keyCode: 49, keyShortcut: "1", funcTriggered: $scope.clickFunction},
{name: 'secondaryTest', keyCode: 50, keyShortcut: "2", funcTriggered: $scope.clickFunction}
]
})
In my HTML directive, I want to specify the object using the name, and then use values from this object. Here is my attempt at a directive so far:
.directive("hotKeyButton", function() {
return {
controller: 'BtnCtrl',
scope: {
hotKeys: '='
},
transclude: true,
template: "<div class='key-shortcut'>{{hotKeys.keyCode}}</div><div class='hotkey-label'>Button</div>"
};
})
So here you can see I want to use the keyCode from the relevant row of the array, but I don't know how to pass in the name. Here is my (incorrect) HTML:
<button hot-key-button name="secondaryTest" class="po-btn secondary-btn" type="submit"></button>
How do I tell my directive to pull data from the secondaryTest object?
Thanks