在元素中调用局部变量导致未定义的错误

时间:2017-06-24 05:49:05

标签: angularjs custom-directive

我尝试创建以下指令

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

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

非常感谢!

1 个答案:

答案 0 :(得分:1)

theValue还是.container{width:500px;height:200px;background-color:#333;display: flex; justify-content: center; align-items: center;} h1{color:#fff;} !您已定义<div class="container"> <h1> Hello Wolrd </h1> </div>,而不是unsigned int b = -1000; std::cout << b << std::endl; printf("%d\n",b);