2016-07-26 20 views
2

私の指示の属性によって、条件付きtemplateURLを使用したいと思います。ここに私のコードは次のとおりです。角条件付きテンプレートURL

MapMarker.js:

app.directive('mapMarker',function(){ 
    return { 
'app/user/ngApp/templates/libsView/templates/directives/map.html', 
     templateUrl : function (elem , attrs) { 
      if (attrs["mapRequire"] == "yes") 
      { 
       console.info("have yes"); 
      } 
      else 
      { 

       console.info("doesn't have yes" , attrs["mapRequire"]); 
      } 
      return attrs["mapRequire"] == "yes" ? 
         'this is text' : '../templates/directives/map1.html'; 
     }, 

HTML:

<map-marker mapRequire = "yes"></map-marker> 

それはdoesn't have yes undefinedを返します。

なぜですか?動的テンプレートURLの提案は属性に依存しますか? しかし、方法は、それが最善の方法ですか?

+0

、これはディレクティブ/属性の命名規則についての関連質問はhttp://stackoverflow.com/questions/33460274/angularjs-directive-naming-conventions/33460305#33460305です – dfsq

答えて

2

標準normalization conventionsを覚えておいてください。 HTMLのkebab-caseはJSのcamelCaseに変換されます。それが必要

は次のようになります。

<map-marker map-require="yes"></map-marker> 
-1

が 選択ディレクティブ

代わりに条件付きURLのしてみてください。

1

すべてのHTML属性はヘビのケースであることを(のみ小文字をし、「 - 」許可されている)持っている。..

と、あなたがそれを使用する必要があります代わりにキャメルケース形式で

をmapRequire属性を使用しています

<map-marker map-require = "yes"></map-marker>