Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ng-repeat in Sightly

I am trying to populate drop-down values using ng-repeat in Sightly. The AEM node saves my data as String array and I am able to fetch it properly, but not able to populate them as it throws "? undefined:undefined ?" error.

My code:

<select name="${validation.elementName}" id="${validation.elementName}" ng-model="${validation.elementName}" ng-change="${properties.clickfunction}">
        <option ng-repeat="opt in ${properties.options}" value={{opt}}>opt</option>                 
        </select>

And the output:

output:

Is there anything I am missing? As Sightly is totally new to me. I will be very grateful for any help to improve this code or pointing my mistake.

like image 581
RIP Nsnd -Lazy pure bot _ Avatar asked Dec 17 '25 17:12

RIP Nsnd -Lazy pure bot _


2 Answers

First of all, you need to wrap the data you pass to value in quotes, so it should be like this:

value="{{opt}}" 

Second, it looks like you are passing the values without single quotes and they are not being recognized as strings. Take a look at this plunker:

http://plnkr.co/edit/A2gZJbvVV9ozHloLkF4B?p=preview

You can see that the first ng-repeat works as expected, but the second throws an error in the console and doesn't display anything. Basically, you just need to put quotes around each string in your array.

like image 61
Victor Marchuk Avatar answered Dec 19 '25 07:12

Victor Marchuk


Thanks @Victor for your reply.

Please find my below findings.

  1. value="{{opt}}" was my mistake while pasting the code to stackoverflow.
  2. ${properties.options} returns string array.
  3. ng-repeat seems to parse correctly as per this output.this
like image 42
RIP Nsnd -Lazy pure bot _ Avatar answered Dec 19 '25 06:12

RIP Nsnd -Lazy pure bot _



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!