我熟悉控制器的語法 & 名但我試圖創建一個通用的指令,將獲得項目的列表,並對每個項目我需要指定一個控制器。通過動態控制器角度指令
這是我的主要指令:
function controlPanel() {
var directive = {
restrict: 'E',
replace: true,
scope: {
controlPanelItems: "=sbControlPanelItems"
},
templateUrl: 'control-panel.html',
link: link
};
return directive;
function link(scope, element) {
}
}
這裏是指令的模板:
<sb-control-panel-item ng-repeat="controlPanelItem in controlPanelItems"
sb-title="controlPanelItem.title"
sb-template-url="controlPanelItem.templateUrl"
sb-control-panel-item-controller="controlPanelItem.controller"></sb-control-panel-item>
我的問題是與SB-控制面板項控制器屬性。
當我傳遞變量時,角度拋出異常,當我傳遞簡單字符串(控制器的名稱)時,它的工作非常好。
這裏是控制面板項指令代碼:
function controlPanelItem() {
var directive = {
restrict: 'E',
replace: true,
scope: {
title: '=sbTitle',
templateUrl: '=sbTemplateUrl'
},
templateUrl: 'control_panel_item.html',
controller: '@',
name: 'sbControlPanelItemController',
link: link
};
return directive;
function link(scope, iElement, iAttributes, controller) {
}
}
也許有一種方法可以通過注入鏈接功能的控制器,然後我就只是將其穿過的範圍?
http://stackoverflow.com/questions/ 16253317/angularjs-turn-ng-controller-name-into-a-directive-variable –