Reputation: 489
I am new to Svelte and I am trying to pass a number value as prop. Here is the code below.
<script lang="ts">
import Infobox from "./Infobox.svelte";
</script>
<Infobox classCount=2 taskCount=6 />
<style></style>
<script lang="ts">
export let taskCount: number;
export let classCount: number;
</script>
<section>
<div>{taskCount} Tasks</div>
<div>Class {classCount}</div>
</section>
<style></style>
I am unable to pass the prop as a number and it is accepting only string like
<Infobox classCount="2" taskCount="6" />
.
I am using typescript as well in this project.
Thanks in advance :)
Upvotes: 6
Views: 1252
Reputation: 489
The right way of passing prop value was using curly braces.
<Infobox classCount={2} taskCount={6} />
This solved the issue.
Upvotes: 9