【发布时间】:2015-10-16 17:00:41
【问题描述】:
我想根据 $watch 动态生成指令。这是我的代码,它只是记录服务对象的值:
gasStation.directive('createMenuTree', ['customerType', function (customerType) {
console.log(customerType.getCustomerType() + ' enterring a directive');
var template;
console.log(customerType.getCustomerType() + ' from directive');
var linker = function(scope){console.log()}
return {
controller: ['$scope', function ($scope) {}],
link: function(scope){
scope.$watch(function(){
console.log(customerType.getCustomerType() + ' watcher');
if (customerType.getCustomerType() == 'REGULAR') {
template = 'dashboard/regular_dashboard.html';
}
if (customerType.getCustomerType() == 'BUSINESS') {
template = 'dashboard/business_dashboard.html';
}
return customerType.getCustomerType();
});
},
templateUrl: template
};
}]);
我是如何使用指令的:<create-menu-tree></create-menu-tree>
问题是:如何根据customerType.getCustomerType() 值设置templateUrl 变量?目前,template 的值未定义。
【问题讨论】:
标签: angularjs angularjs-directive directive