2017-01-24 2 views
0

Ich habe dieses angulare Skript, um ein div. Aufzubauen. Das Problem, das ich habe, ist, dass es den .text innerhalb des i Etiketts anhängt und nicht als ein Geschwister von i.Append "i" -Tag plus Text zu überspannen

Hope das macht Sinn.

  var body = placeWrapper 
       .append('div') 
       .attr('class', 'thm-listing__body'); 

       body.append('span') 
       .attr('class', 'thm-listing__location') 
       .append('i') 
       .attr('class', 'fa fa-map-marker') 
       .text(function (d) { 
        return d.Address; 
       }); 

wird dieser Tauchgang wie folgt zu rendern annehmen:

<div class="thm-listing__body"> 
<span class="thm-listing__location"> 
<i class="fa fa-map-marker"></i> 
The text here 
</span> 
</div> 

Aber es macht derzeit aus:

<div class="thm-listing__body"> 
<span class="thm-listing__location"> 
<i class="fa fa-map-marker">The text here</i> 
</span> 
</div> 
+0

Das ist nicht die Art und Weise * Angular * ... – Mistalis

Antwort

0

Du text-i Tag einstellen und Sie möchten einen Text für spanne rechts, also setze den Text direkt nach dem append span statt nach dem append i wie unten

var body = placeWrapper 
     .append('div') 
     .attr('class', 'thm-listing__body'); 

     body.append('span') 
     .attr('class', 'thm-listing__location') 
     .text(function (d) { 
      return d.Address; 
     }) 
     .append('i') 
     .attr('class', 'fa fa-map-marker'); 

aktualisiert

Set-Symbol vor der Spanne Text Verwendung prepend() nach unten

var body = placeWrapper 
      .append('div') 
      .attr('class', 'thm-listing__body'); 

      body.append('span') 
      .attr('class', 'thm-listing__location') 
      .text(function (d) { 
       return d.Address; 
      }) 
      .prepend('i') 
      .attr('class', 'fa fa-map-marker'); 
+0

Es vor dem Text sein muß, ich habe versucht Es ist so, aber dann sitzt das Symbol am Ende des Textes und nicht am Anfang. –

+0

Finden Sie meine aktualisierte Antwort verwenden 'prepend()' für diese – Curiousdev

+0

Nein, es scheint nicht zu funktionieren: body.append (...). Attr (...). Text (...). Prepend ist kein Funktion ist der Fehler, den ich bekomme, wenn ich wie oben –