0
我有麻烦找到完全动态指令的解决方案。我使用angular-gridster库对仪表板页面的图块进行概述。我想通过一个灵活的指令动态加载一些特定的图块。动态控制器和templateUrl注入角度指令
<div gridster="vm.model.gridsterOptions">
<ul>
<li gridster-item="tile.tileParams.gridParams" ng-repeat="tile in vm.model.dashboards.tiles">
<div class="box" ng-controller="tileGrid_TileController">
<eg-tile template-url={{tile.tileEngine.tempUrl}}
controller-name={{tile.tileEngine.tileCtrl}}>
</eg-tile>
</div>
</li>
</ul>
</div>
我创建了egTile指令:
(function() {
function implementation() {
return {
restrict: 'E',
transclude: true,
scope: true,
controller: '@',
bindToController:true,
controllerAs: 'vm',
name: 'controllerName',
templateUrl: function (elem, attrs) {
return attrs.templateUrl || 'app/module/tileGrid/view/templates/empty.html';
}
};
}
var declaration = [implementation];
angular.module('app.tileGrid').directive('egTile', declaration);
}());
,如果我在egTile指令使用固定字符串像
<eg-tile template-url="string_url" controller-name= "string_ctrl"></eg-tile>
该指令将工作,但我想要动态选择控制器和templateUrl。 我已经尝试使用$ parse和$ observe服务,但没有成功。 这甚至有可能使指令如此灵活吗?
在此先感谢