2016-06-14 6 views
2

に評価していない:属性は、私は以下の角度指令が動作していない理由として混乱しています角度指令

JS

angular 
    .module("app") 
    .directive("symbolImage", function() { 
     return { 
      restrict: 'AE', 
      scope: { 
       width: "@", 
       height: "@", 
       symbol: "@" 
      }, 
      template: "<div>{{width}} {{height}} {{symbol|json}}</div>", 
      replace: true 
     }; 
    }); 

変数

$scope.current = {prop1:{foo:"bar"}, prop2:{foo2:"bar2"}}; 
$scope.properties = ["prop1", "prop2"]; 

HTML

<tr ng-repeat="prop in properties"> 
    <td> 
     <symbol-image height="20" width="20" symbol="current[prop]"/> 
    </td> 
</tr> 

期待されるOUTP UT(第リピート)

20 20 {foo:"bar"} 

実際の出力(第リピート)

20 20 "current[prop.key]" 

それは(あった)である私の理解では、スコープに渡された値が評価されますが、これはケースではないようです。

いずれか/すべての援助が評価されます。

+0

変更 '記号:「@」'へ 'シンボル: "=" ' –

+0

ありがとう!出来た。 –

答えて

2

は、あなただけの「@」

<symbol-image height="20" width="20" symbol="{{current[prop]}}"/> 

を使用する必要がありますあなたはディレクティブに文字列を与えることを期待しています。 '='ディレクティブにオブジェクトを渡す必要があります。あなたの問題を解決するための別の方法は、このようなあなたのディレクティブを定義することであっただろう

 scope: { 
      width: "@", 
      height: "@", 
      symbol: "=" 
     }, 
+0

ありがとうございました! –

0

あなたの小道具をdeclarateする必要があり、このよう

 scope: { 
      width: "@", 
      height: "@", 
      symbol: "=" 
     }, 
関連する問題