angular-slider icon indicating copy to clipboard operation
angular-slider copied to clipboard

Broken inside ng-repeat

Open mattosborn opened this issue 11 years ago • 9 comments

Doesn't work inside an ng-repeat. http://plnkr.co/edit/QcOj4mZKxz5rmsSC1wun?p=preview

mattosborn avatar Jul 11 '13 20:07 mattosborn

The reason is that the ng-repeat does not add the compiled dom elements until the repeater finishes with all items (they do not have any dimensions when the post-link function executes). Not sure about the solution though, as the slider-directive should recalculate positions/dimensions on window resize...

bitbay avatar Jul 11 '13 20:07 bitbay

Ok, the following issues are manifestations of the same problem: #12 #10 #8 #6

Basically, when the directive's code kicks in, if it's dom data is not rendered for some reason (hidden at first in bootstrap tabs, waiting for other elements to compile in ng-repeat, etc), the code fails.

I'll close all these issues and open another that I'll post updates on. I'll hack on the code tomorrow; I'm thinking setting up a watcher on the parent's width might work. But this still leaves the Bootstrap tab issue, where querying fullBar.width even after tabs are initialized and slider is visible still returns 0.

prajwalkman avatar Jul 12 '13 01:07 prajwalkman

Sounds great!

bitbay avatar Jul 12 '13 23:07 bitbay

Hi, I just meet the ng-repeat issue. prajwalkman, have you investigated watching the parent's width?

fkhbgm avatar Jul 24 '13 00:07 fkhbgm

Sorry guys, I just moved to a new country and still trying to get my stuff in order. Don't have laptop or broadband yet, progress will be slow for a while. If someone wants to take over in the interim, get in touch with my @ [email protected]

prajwalkman avatar Aug 20 '13 00:08 prajwalkman

Hello ! Did you solved this problem ? What do you think about re-compile on window onload and custom event ($compile(element)(scope);) ?

superjem avatar Oct 08 '13 09:10 superjem

Dont forget you can always use "range" :

        <li data-ng-repeat="skill in skills">
          <input ng-model="skill.weight" type="range" min="0" max="9" step="1" value="{{skill.weight}}"/>
          <!-- <slider floor="0" ceiling="10" step="1" precision="1" data-ng-model="skill.weight"></slider> -->
        </li>

If you need legacy browser support I would imagine this might work with existing polyfills?

haveaguess avatar Oct 24 '13 00:10 haveaguess

Just my two cents, please update the Readme about this issue accordingly since it will help others from blocking for several hours getting this work inside a ng-repeat before seeing this thread :)

passkey1510 avatar Nov 19 '13 08:11 passkey1510

The problem is that the slider is saving a reference to its elements in the compile function, which aren't necessarily valid once it gets to the linking stage. The bit of code that assigns fullBar, selBar, minPtr, etc. just needs to be copied to the top of the compile function, and slightly modified to handle differences between single and range mode.

ricochet1k avatar Nov 26 '13 17:11 ricochet1k