javascript - Most sensible way to insert DOM element at specific point within ng-repeat? -


i'm looking create podcast player application using angularjs.

so far, i've got list of podcasts available play, using ng-repeat, looks this.

<ul ng-controller="list">   <li ng-repeat="podcast in podcasts" ng-click="startplaying()">     <p>{{podcast.created_time | date}}</p>     <div class="podcast-icon" style="background-image:url('{{podcast.icon}}')">       <i class="fa fa-play"></i>     </div>     <h3>{{podcast.name}}</h3>     <p>{{podcast.duration}}m</p>   </li> </ul> 

these displaying in responsive flexbox grid, , want want function startplaying trigger player appear, on row below clicked item, similar netflix.

i'm confused how to:

  1. get index of <li> element at end of row of clicked element, given grid responsive , number of <li>s on each row changes viewport.
  2. tell angular insert new dom element after particular index in ng-repeat.

i suppose infer number of <li>s per row width of parent, window.getcomputedstyle(ul).width, seems roundabout. there better way?

thanks!

you can access index of li following:

{{$index}} 

or even:

{{podcasts.indexof(podcast)}} 

if fed click event add element in corresponding function, this:

<li ng-repeat="podcast in podcasts" ng-click="startplaying($index)"> 

but need select correct element give li class:

<li class="podcast" ng-repeat="podcast in podcasts" ng-click="startplaying($index)"> 

then in startplaying function select element index , append element:

$scope.startplaying = function(index) {   var podcasts = document.getelementsbyclassname('podcast')   var currentpodcast = podcasts[index]   angular.element(currentpodcast).append('<html></html>'); } 

just replace <html></html> element want append.


Comments

Popular posts from this blog

javascript - Create a stacked percentage column -

Optimising Firebase database by automatically overwriting data -

javascript - Angular UI-Grid customTemplate directive causing rows to load slowly/? -