Created
May 22, 2024 19:59
-
-
Save rakia/2420669f33dd82495f7f09fbcd1fee82 to your computer and use it in GitHub Desktop.
Angular: Model input example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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