0

我尝试创建以下指令

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

有谁知道如何在元素中调用局部变量?

非常感谢!

4

1 回答 1

1

theValue还是thValue!你已经定义了thValue,不是theValue

于 2017-06-24T05:51:07.307 回答