我尝试创建以下指令
function sortingTableHeader($compile) {
return {
link: function(scope, element, attrs) {
var tableHeaderEles = angular.element(element[0].querySelectorAll('th'));
angular.forEach(tableHeaderEles, function(tableHeaderEle) {
var thElement = angular.element(tableHeaderEle);
var thValue = thElement.text();
var sortIcon = '<span class="fa" ng-init="abc=' + theValue + '" ng-class="{\'fa-sort\': sortType != abc}">{{abc}}</span>';
thElement.append($compile(sortIcon)(scope));
});
}
};
}
我试图在元素中调用 theValue 变量,它会引发错误:
angular.js:14525 ReferenceError: theValue is not defined
有谁知道如何在元素中调用局部变量?
非常感谢!