-1

I tried using <div>{{ objectkey.keys(numberOfComment['post_1']).length }} Comments</div> in angularjs2 project but it is throwing error "cannot read property of undefined objectkey.keys(numberOfComment['post_1']).length " but it is working in the js (prints in the console).

i tried to implement as mentioned this link Unable to call Object.keys in angularjs

this.objectkey = { keys : Object.keys } in the js file.

<div>{{ objectkey.keys(numberOfComment['post_1']).length }} Comments</div> in html

Community
  • 1
  • 1
Akash Rao
  • 920
  • 3
  • 12
  • 25

1 Answers1

3

Change to:

this.objectkey = { 
     keys : function(){ 
        return Object.keys(numberOfComment['post_1']).length 
     } 
}

and in the html

<div>{{ objectkey.keys() }} Comments</div>
Jai
  • 74,255
  • 12
  • 74
  • 103