Get variable from alpine.js and add it to placeholder

Viewed 2358

I am trying to fetch a variable from an alpinejs format to put into placeholder of my input, the code is as follows:

<template x-for="(field, index) in fields" :key="index">
    <input type="text" name="sort" placeholder="<want to put index here>" />
</template>

Is this possible?

1 Answers

Try this:

<template x-for="(field, index) in fields" :key="index">
    <input type="text" name="sort" x-bind:placeholder="index" />
</template>
Related