0

When trying to print the custom object by iterating through the for loop via ngFOR the double quotes are also being printed Here is my loop the value is being printed like this "METRO" while i want them to appear normal like METRO

<ion-list>
  <ion-item-group *ngFor="let g of tp.LegList">
    <table width="100%" border="0">
      <tbody>
        <tr>
          <th>
            <ion-card>
              <div *ngIf="g" ng-value="some value">
                {{g}} {{g.line}}
                <ion-item>
                  <ion-label (click)="showNextDepartures($event)">{{g.line | json}}</ion-label>
                </ion-item>
              </div>
            </ion-card>
          </th>
        </tr>
      </tbody>
    </table>
  </ion-item-group>
</ion-list>
</ion-item-group>
</ion-list>
Farrukh Qamar
  • 93
  • 1
  • 10
  • `{{g}} {{g.line}}` are you printing entire object? also which line in the code prints METRO? – Suraj Rao Jan 20 '17 at 08:43
  • {{g.line | json}} g.line > should print 18 while "18" is being printed i am iterating through the array of custom class object. g has all the members .One of them is line and another is type when i access them via g.line or g.type then double quotes are being printed while i want them to print without double quotes – Farrukh Qamar Jan 20 '17 at 08:54
  • why are you sending to json pipe? That is used to pretty print entire object not a property – Suraj Rao Jan 20 '17 at 09:01
  • hi, i just tried without json and it is now being printed without quotes.Here is the right one {{g.line}} insted of {{g.line | json}} – Farrukh Qamar Jan 20 '17 at 09:02
  • http://stackoverflow.com/questions/37308420/angular-2-pipe-that-transforms-json-object-to-pretty-printed-json – Suraj Rao Jan 20 '17 at 09:02

1 Answers1

0

Try without json pipe. Json pipe is used to pretty print entire object and not a specific property.

<ion-label (click)="showNextDepartures($event)">{{g.line}}</ion-label>
Suraj Rao
  • 29,388
  • 11
  • 94
  • 103
  • pipe would work if you did {{g | json}} . It is generally used to debug json content. Havent seen it used to display anything since it pretty prints – Suraj Rao Jan 20 '17 at 09:10