Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getter method is not working #13

Open
yusuftaufiq opened this issue Oct 13, 2022 · 0 comments
Open

Getter method is not working #13

yusuftaufiq opened this issue Oct 13, 2022 · 0 comments

Comments

@yusuftaufiq
Copy link

Hi there, I have a problem using the getter method. It seems that the getter method doesn't work in class components.

To be clear, I have the following components:

import { AlpineComponent } from '@leanadmin/alpine-typescript';
import User from '../interfaces/user'

export default class Contact extends AlpineComponent {
  public contacts: User[] = []

  public search: string = ''

  public init(): void {
    this.contacts = [
      { id: 1, name: 'smith' },
      { id: 2, name: 'john' },
      { id: 3, name: 'doe' },
      { id: 4, name: 'jean' },
    ]
  }

  public get filteredContacts(): User[] {
    return this.contacts.filter(({ name }: User): boolean => name.includes(this.search))
  }
}

And then when used on the view using the following code:

<input x-model="search" type="text" placeholder="Search users">
<ul>
  <template x-for="contact in filteredContacts">
    <li x-text="contact.name"></li>
  </template>
</ul>

It seems that filteredContacts is always stuck with the initial value and doesn't update dynamically. Is there a way to fix this, or maybe I'm missing something?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant