2013-09-30 4 views
0

문자열 변수를 템플릿의 내용으로 설정할 수 있습니까? 범위에 따라 두 개의 다른 템플릿을 선택하고 싶습니다. 다음과 같이 입력하십시오 :지시어 템플릿 내용으로 변수 참조하기

define(['app'], function(app){ 
    app.directive('logstorelist', function(){ 
     var temp=""; 
     return{ 
      scope: true, 
      restrict: 'A', 
      link: function(s, e, a){ 
       if(a=="a") 
        temp = "<a>tempA</a>"; 
       else 
        temp = "<div>temp</div>"; 
      }, 
      replace: true, 
      template: temp 
     } 
    }) 
}); 

이게 뭔가요?

답변

1

당신은 하나의 템플릿을 사용하고 (당신이 여분의 <span> 마음을하지 않는 경우) 범위 변수에 따라 내용을로드 ng-switch을 사용할 수

define(['app'], function(app){ 
    app.directive('logstorelist', function(){ 
     var temp=""; 
     return{ 
      scope: true, 
      restrict: 'A', 
      link: function(s, e, a){ 
       s.temp = a; 
      }, 
      replace: true, 
      template: 
      ' <span ng-switch="temp"> 
       <a ng-switch-when="a">tempA</a> 
       <div ng-switch-default>temp</div> 
      </span>' 
     } 
    }) 
}); 
+0

들으을, 그것은 매우 잘 작동 :) 가 내가 아직도 알아야 할 많은 기능들이있다. – marcel

+0

오, 나는 그것이 "temp"에 ng-switch가 아니라고 말해야합니다. 그것은 ng-switch = "temp"입니다 ... – marcel

+0

나는 그것을 편집 할 것입니다! :) –

관련 문제