2013-06-14 2 views
2

다음 지시문에서 {{selectedForApproval.length}}을 평가하고 싶습니다. 이것은 지시어가 아닐 때 작동했지만 일단 지시문에 넣으면 바인딩을 처리하는 방법을 알 수 없습니다.{{}}이 (가) 포함 된 속성을 평가하는 방법

HTML : <button-large color="green" ng-click="completeWork()" label="Approve Selected ({{selectedForApproval.length}})"></button-large>

지침 :이 솔루션은 트랜스 클루 전을 사용하는 것이었다

directive('buttonLarge', function() { 
    return { 
     scope: false, 
     replace: true, 
     restrict: 'E', 
     template: '<button type="checkbox" class="buttonL"/>', 
     link: function (scope, element, attrs) { 
      var config = { 
       label: "Submit", 
       color: "Default" 
      }; 

      angular.extend(config, attrs); 

      element.addClass("b"+capitalize(config.color)); 
      element.html(scope.$parent.$eval(config.label)); 

      //capitalize first letter of string 
      function capitalize(s) { 
       return s[0].toUpperCase() + s.slice(1); 
      } 
     } 
    } 
}) 

답변

1

...

<button-large color="green" ng-click="completeWork()">Approve Selected ({{selectedForApproval.length}})</button-large>

directive('buttonLarge', function() { 
     return { 
      scope: false, 
      replace: true, 
      restrict: 'E', 
      transclude: true, 
      template: '<button type="checkbox" class="buttonL" ng-transclude/>', 
      link: function (scope, element, attrs) { 
       var config = { 
        color: "Default" 
       }; 

       angular.extend(config, attrs); 

       element.addClass("b"+capitalize(config.color)); 

       //capitalize first letter of string 
       function capitalize(s) { 
        return s[0].toUpperCase() + s.slice(1); 
       } 
      } 
     } 
    }) 
관련 문제