Skip to content

Instantly share code, notes, and snippets.

@zuzkins
Created June 2, 2016 07:14
Show Gist options
  • Save zuzkins/25f0dd8d1d31af6d8a057f92cd6101d2 to your computer and use it in GitHub Desktop.
Save zuzkins/25f0dd8d1d31af6d8a057f92cd6101d2 to your computer and use it in GitHub Desktop.
TIL you can put @input() decorator on setter and transform the value. It does not have to be put on property.
@Component( selector: 'user-role',
template: r'''
<span *ngIf="userRole != null && long" >{{ userRole.completeLabel }}</span>
<span *ngIf="userRole != null && !long" >{{ userRole.label}}</span>
''')
class UserRoleComponent {
UserRole userRole;
@Input()
bool long = false;
@Input()
set role(var role) {
if (role is UserRole) this.userRole = role as UserRole;
final UserRole found = findRoleDescriptor(role);
this.userRole = found;
}
}
@kraag22
Copy link

kraag22 commented Jun 2, 2016

no 4th line there is space missing :-D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment