Skip to content

Instantly share code, notes, and snippets.

<app-toolbar></app-toolbar>
<app-habit-form *ngIf="formOpen; else allHabits"
(onExit)="closeForm()"
[habit]="editHabit"></app-habit-form>
<ng-template #allHabits>
<app-all-habits
(addEvent)="onAdding()"
export class HabitFormComponent implements OnInit {
@Output() onExit = new EventEmitter();
@Input() habit: Habit;
public editingIndex: number;
public habits: Habit[];
public habitForm = new FormGroup({
name: new FormControl(''),
frequency: new FormControl(''),
description: new FormControl(''),
import { Component, OnInit } from '@angular/core';
import { Habit } from './models/habit';
// ...Code Omitted...
export class AppComponent implements OnInit {
public formOpen = false;
public editHabit: Habit;
// ...Code Omitted...
<!--...Code Omitted...-->
<div *ngFor="let habit of habits; let i = index">
<mat-card>
<mat-card-title>
<mat-icon
class="habit-icon"
color="accent"
aria-hidden="false"
aria-label="circle check mark icon"
>check_circle_outline</mat-icon
export class AllHabitsComponent implements OnInit {
@Output() addEvent = new EventEmitter();
@Output() editEvent = new EventEmitter<Habit>();
public habits: Habit[];
constructor() {}
ngOnInit(): void {
this.habits = HABITS;
export class AppComponent implements OnInit {
public formOpen = false;
ngOnInit(): void {}
onAdding() {
this.formOpen = true;
}
closeForm() {
export class HabitFormComponent implements OnInit {
@Output() onExit = new EventEmitter();
// ...Code Omitted for Brevity...
exitForm() {
this.habitForm.reset();
this.onExit.emit();
}
}
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss'],
})
export class AppComponent implements OnInit {
public formOpen = false;
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss'],
})
export class AppComponent implements OnInit {
public formOpen = false;
<div class="all-habits">
<h1>All Habits</h1>
<button mat-raised-button color="accent" (click)="onAdd()">
Add New Habit
</button>
<div *ngFor="let habit of habits; let i = index">
<mat-card>
<mat-card-title>
<mat-icon
class="habit-icon"