Skip to content

Instantly share code, notes, and snippets.

@rakia
Created May 22, 2024 19:59
Show Gist options
  • Save rakia/2420669f33dd82495f7f09fbcd1fee82 to your computer and use it in GitHub Desktop.
Save rakia/2420669f33dd82495f7f09fbcd1fee82 to your computer and use it in GitHub Desktop.
Angular: Model input example
import { Component, model, input } from '@angular/core';
@Component({
selector: 'app-user',
template: '<button (click)="upgradeSubscription()">Upgrade Subscription</button>',
})
export class UserComponent {
// a standard input, it's read-only
isSubscribed = input(true);
// a model input, two-way binding
isPremium = model(false);
upgradeSubscription() {
// write directly to the model input
this.isPremium.set(!this.isPremium());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment