4
我有一個指令根據作爲屬性發送的數組構建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){
}
}
}
});
感謝