How can I get a single array lenght?

Hello guys, I want to display the number of the array, separately, like:


But I’m getting only the total length, like number 10.


Can anyone help me solve this? Thanks.

What do you mean by displaying?

If you mean render them in html, using ng-repeat will solve your problem.

<div ng-repeat="num in YourArray">

ng-repeat is an angular directive, visit official ng-repeat for more detailed introduction.

The $index above will be the absolute position of the element in the array, “$index+1” may be the thing you want to display.

The “num” is a renamable (call it anything you want in ngrepeat) iteration of every object in the array, you can use it just like YourArray[$index].

Hope this helps.

1 Like

Thanks Windht, but what I’m trying to do is to get the post title using the social sharing, like:

<button onclick="window.plugins.socialsharing.share(post.title)">message only</button>

I don’t now how to make it work…

Well I checked the github page of socialsharing, this function is indeed passing in an string to work, assume you have all the setup done, I suggest you to wrap the function in an angular way.

By angular way, meaning using “ng-click” rather than “onclick”,

So change your html to:

<button ng-click="share(post.title)">

Then in your controller (I suggest you know what is $scope):


Indeed, ionic team has done a wrap up of the social sharing function for angular at Social Sharing ngCordova. Do check it out because it is a more standard way of doing so in an ionic app.

Using angular meaning that scope isolation is something you have to consider all the time. So your old way may not be able to correctly passing in the “post.title”, feel free to ask if you have any more problems on this.

1 Like