我在對象數組中存儲按鈕快捷方式類型的負載。我想寫一個指令,將返回取決於對象的名稱的一些值。這裏是我的陣列存儲在控制器內:如何使指令引用數組中的特定行 - 角度
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}
]
})
在我的HTML指令,我要指定使用name
的對象,然後從該對象使用的值。這是我在一個指令嘗試至今:
.directive("hotKeyButton", function() {
return {
controller: 'BtnCtrl',
scope: {
hotKeys: '='
},
transclude: true,
template: "<div class='key-shortcut'>{{hotKeys.keyCode}}</div><div class='hotkey-label'>Button</div>"
};
})
所以在這裏你可以看到我想從數組的相關行使用keyCode
,但我不知道如何在name
通過。這裏是我的(不正確)HTML:
<button hot-key-button name="secondaryTest" class="po-btn secondary-btn" type="submit"></button>
我如何告訴我的指令,從secondaryTest
對象提取數據?
感謝
好評論...三江源。我不想使用中繼器,因爲這些按鈕可能位於頁面的各個位置,它們不一定會重複。這更適合存儲我的鍵盤快捷鍵。 – MDalt
@MDalt根據附加信息編輯 – Icycool
Amazin。這工作。謝謝! – MDalt