You have oversimplified your example here, then. I pasted it directly into a sample project, fixed the off-by-one bug, and it works fine.
Is it possible that you’re not actually initializing the array in the constructor as you describe here, but are instead doing it from storage or a network request or some other asynchronous event?
You don’t think the page is rendering too quickly on his machine? I believe you that it works. But just on principIe I would put this.mydata = new Array<Object>() in the constructor, and put the “real” definition in ngOnInit(). Maybe I’m paranoid, but I don’t put any actual computation in constructors anymore.
Also, I wouldn’t actually use Array<Object>(). I’d strongly type the whole file. But that’s a different conversation.
Not quite sure what you mean here, but this sounds like the sort of thing that qualifies as a race condition. Those are tough to diagnose and debug, which is why:
I don’t put any actual computation in constructors
I do, although in practice there may not be much difference between doing it there and in ngOnInit. I wholeheartedly agree with your other points regarding initialization (although I do it inline instead of in constructors) and strong typing.
actually my problem is that i am getting the datas while printing in console, but not in html
Your machine is trying to build the DOM before your array is defined. When you log to the console later, it is after your array is defined. So you need to define the array before the DOM is rendered. Do that in the constructor. After your array is defined, you can populate it with values however you want.
Put your initialization statements at the beginning of the constructor – the lines like this.foo = new Bar();
Make sure that every variable you refer to in your template is defined like that in the constructor. Only after all variables are defined, start doing computation. This is especially important when your computation is inherently asynchronous, like an Observable subscription, a Promise or a callback.
By the way, there are a lot of stylistic problems with your code. My suggestion would be that you spend some time with tutorials on TypeScript and Angular 2 before continuing to program in Ionic. Things that seem impossible right now will become obvious.