1

Here is my function that takes resLS as an object array. I am trying to display arr in html element using Angular 4. But when I do {{arr}}, I don't see anything in html. I was expecting to see some element appended in arr array and I definitely see data in console. What am I missing?

findLastValueLS(resLS, name: String) {
let index = resLS.NewDataSet.Table.findIndex(d => d.DataPointName[d.DataPointName.findIndex(DataPointName => DataPointName === name)]);
console.log(resLS.NewDataSet.Table[index].LastValue);
var arr = []; 
arr.push(resLS.NewDataSet.Table[index].LastValue);
}
4
  • Can you add your html code Commented Oct 25, 2017 at 13:30
  • it's just <div> {{arr}}</div> Commented Oct 25, 2017 at 13:31
  • You can use the JSON pipe for this {{ arr | json }}. Or even <pre>{{ arr | json }}</pre> for a more readable output. Commented Oct 25, 2017 at 13:32
  • still not seeing anything Commented Oct 25, 2017 at 13:35

2 Answers 2

4

Use ngFor :

  <div *ngFor="let item of arr">
      Name : {{ item }}
  </div>
Sign up to request clarification or add additional context in comments.

12 Comments

i don't get any item values.
I just checked. It lists of array as expected in console.
<button (click)="logMe()"> </button>
i replaced logMe() with my function, and once I click it says that it cannot read property of object somehow .. why is that ?
outside the function arr is null so it will not populate values , you have to make it ouside and use this.arr inside
|
0

Use *ngFor if you are using Angular, or ng-repeat if you are using AngularJS. See the documentation:

AngularJS : https://docs.angularjs.org/api/ng/directive/ngRepeat Angular:https://angular.io/api/common/NgForOf

Sample for Angular:

<div *ngFor='item of arr'> {{item}} </div>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.