【发布时间】:2013-05-04 22:38:59
【问题描述】:
我有一个基于作为属性发送的数组构建 html 的指令。我无法从指令的编译器函数访问它。它在链接函数中工作,但我需要在编译中,否则新模板不会被编译。
代码是这样的:
<multirangeslider values="ranges" variances="['Master', 'master A', 'master B']"></multirangeslider>
指令:
angular.module("vtApp.directives").
directive('multirangeslider', function ($parse, $timeout, $compile) {
return {
restrict: 'E',
replace: true,
scope: {
values: "=",
options: "=",
variances: "&"
},
compile: function (element, attrs) {
var htmlText, variances, values;
variances = eval(attrs.variances);
values = scope.ranges //scope is undefined
values = eval (attrs.variances) //returns string "ranges"
values = ??? ///what should I put here?
htmlText = '<div></div>';
element.replaceWith(htmlText);
return function (scope, element, attrs){
}
}
}
});
谢谢
【问题讨论】:
标签: javascript angularjs-directive compiler-directives