src/app/components/assignment-card/assignment-card.component.ts
OnInit
selector | apollo-assignment-card[assignment] |
styleUrls | ./assignment-card.component.scss |
templateUrl | ./assignment-card.component.html |
Properties |
|
Methods |
|
Inputs |
assignment | |
Type : Assignment
|
|
Public ngOnInit |
ngOnInit()
|
Returns :
void
|
Public Optional shortenedDescription |
Type : string
|
import { Component, Input, OnInit } from '@angular/core';
import { Assignment } from 'src/app/model/api/assignment';
const maxShortenedDescriptionLength = 100;
@Component({
selector: 'apollo-assignment-card[assignment]',
templateUrl: './assignment-card.component.html',
styleUrls: ['./assignment-card.component.scss'],
})
export class AssignmentCardComponent implements OnInit {
@Input()
public assignment!: Assignment;
public shortenedDescription?: string;
public ngOnInit(): void {
const description = this.assignment.description;
if (description === undefined) {
return;
}
if (description.length <= maxShortenedDescriptionLength) {
this.shortenedDescription = description;
return;
}
this.shortenedDescription = description.substring(0, maxShortenedDescriptionLength - 3).concat('...');
}
}
<div>
<mat-card>
<mat-card-title>
{{ assignment.title }}
</mat-card-title>
<mat-card-subtitle>
{{ assignment.completedOn ? ("assignments.completed-on" | translate: { date: (assignment.completedOn | date) }) : ("assignments.not-completed" | translate) }}
</mat-card-subtitle>
<mat-card-content *ngIf="shortenedDescription">
{{ shortenedDescription }}
</mat-card-content>
<mat-card-actions style="display: flex; justify-content: flex-end">
<button mat-button color="accent" [routerLink]="assignment.id">{{ "actions.open" | translate }}</button>
</mat-card-actions>
</mat-card>
</div>
./assignment-card.component.scss
:host {
display: block;
}