Ich möchte bedingte VorlageURL durch Attribut in meiner Direktive verwenden. hier ist mein Code:Angular bedingte VorlageURL
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>
Es doesn't have yes undefined
zurückzukehren.
Warum? Jeder Vorschlag für eine dynamische Vorlagen-URL hängt vom Attribut ab? Aber der Weg, ist es der beste Weg?
ist damit verbundene Frage nach Richtlinie/Attribut Namenskonventionen http://stackoverflow.com/questions/33460274/angularjs-directive-naming-conventions/33460305#33460305 – dfsq