我有一个基于作为属性发送的数组的指令构建 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){
}
}
}
});
感谢