Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save realtomaszkula/3f0aaaa0f0a2b8c36e3cad67da6633f4 to your computer and use it in GitHub Desktop.
Save realtomaszkula/3f0aaaa0f0a2b8c36e3cad67da6633f4 to your computer and use it in GitHub Desktop.
import { Component } from '@angular/core';
type Label<T extends object> = { [key in keyof T]: string };
type PartialLabel<T extends object> = { [key in keyof Partial<T>]: string };
interface LoginForm {
username: string;
password: string;
}
@Component({
selector: 'app-form',
template: `
<form>
<input [(ngModel)]="login.username" name="username" [placeholder]="placeholders.username" />
<input [(ngModel)]="login.password" name="password" [placeholder]="placeholders.password" />
<div> {{ hints.password }} </div>
</form>
`
})
export class FormComponent {
login: LoginForm = {
username: '',
password: ''
};
placeholders: Label<LoginForm> = {
username: 'Username',
password: 'Password'
};
hints: PartialLabel<LoginForm> = {
password: 'Must contain at least one special character'
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment