MPT Micro Project - Removed
MPT Micro Project - Removed
Code:
add-btn.component.ts
@Component({
selector: 'app-add-btn',
templateUrl: './add-btn.component.html',
styleUrls: ['./add-btn.component.scss']
})
export class AddBtnComponent {
closeResult = '';
nTitle: string | undefined;
nText: string | undefined;
@Input() nId: number | undefined;
@Output() newNoteData: EventEmitter<NoteInterface> = new EventEmitter();
open(content): void {
this.modalService.open(content, {ariaLabelledBy: 'modal-basic-title', size:
'lg'}).result.then((result) => {
this.closeResult = `Closed with: ${result}`;
}, (reason) => {
this.closeResult = `Dismissed ${this.getDismissReason(reason)}`;
});
}
newNote(): void {
if (this.nTitle.trim().length > 4 && this.nText.trim().length > 4) {
const nItem = {
id: ++this.nId,
title: this.nTitle,
text: this.nText
};
this.newNoteData.emit(nItem);
this.modalService.dismissAll();
this.nTitle = '';
this.nText = '';
}
}
}
app.component.ts
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
})
export class AppComponent {
title = 'Simple Notepad App';
}
app.module.ts
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
@NgModule({
declarations: [
AppComponent,
ContainerComponent,
NoteItemComponent,
AddBtnComponent
],
imports: [
BrowserModule,
NgbModule,
BrowserAnimationsModule,
MatIconModule,
FormsModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
container.component.ts
@Component({
selector: 'app-container',
templateUrl: './container.component.html',
styleUrls: ['./container.component.scss']
})
export class ContainerComponent {
@Input() title: string;
notes: NoteInterface[] = [
{id: 1, title: 'Note Name', text: 'Note Text'},
{id: 2, title: 'Example 1', text: 'Text example'},
{id: 3, title: 'End application', text: 'Implement all features notepad application'}
];
constructor() {
}
onNewNote(item): void {
this.notes.push(item);
}
@Component({
selector: 'app-note-item',
templateUrl: './note-item.component.html',
styleUrls: ['./note-item.component.scss']
})
export class NoteItemComponent {
optionsShow = false;
editMode = false;
@Input() noteItem: NoteInterface;
@Input() itemIndex: number;
@Output() dellItemId: EventEmitter<number> = new EventEmitter<number>();
@Output() updateItem: EventEmitter<NewNoteInterface> = new
EventEmitter<NewNoteInterface>();
constructor() {
}
deleteItem(): void {
this.dellItemId.emit(this.itemIndex);
}
startEditMode(): void {
this.editMode = true;
}
endEditMode(): void {
if (this.noteItem.title.trim().length > 4 && this.noteItem.text.trim().length > 4) {
this.editMode = false;
const updatedItem: NewNoteInterface = {
index: this.itemIndex,
newItem: this.noteItem
};
this.updateItem.emit(updatedItem);
}
}
}
note-item.component.html
<div
class="border rounded border-success m-3 p-3"
(mouseenter)="optionsShow = true" (mouseleave)="optionsShow = false">
<h2 [hidden]="editMode">{{noteItem.title}}</h2>
<p [hidden]="editMode">{{noteItem.text}}</p>
<input type="text" class="form-control" placeholder="{{noteItem.title}}"
[(ngModel)]="noteItem.title" [hidden]="!editMode">
<input type="text" class="form-control" placeholder="{{noteItem.text}}"
[(ngModel)]="noteItem.text" [hidden]="!editMode">
<div>
<button class="btn btn-danger" [hidden]="!optionsShow"
(click)="deleteItem()">Delete</button>
<button class="btn btn-secondary ml-3" [hidden]="!optionsShow || editMode"
(click)="startEditMode()">Edit</button>
<button class="btn btn-secondary ml-3" [hidden]="!editMode"
(click)="endEditMode()">Save</button>
</div>
</div>
note-item.component.ts
@Component({
selector: 'app-note-item',
templateUrl: './note-item.component.html',
styleUrls: ['./note-item.component.scss']
})
export class NoteItemComponent {
optionsShow = false;
editMode = false;
@Input() noteItem: NoteInterface;
@Input() itemIndex: number;
@Output() dellItemId: EventEmitter<number> = new EventEmitter<number>();
@Output() updateItem: EventEmitter<NewNoteInterface> = new
EventEmitter<NewNoteInterface>();
constructor() {
}
deleteItem(): void {
this.dellItemId.emit(this.itemIndex);
}
startEditMode(): void {
this.editMode = true;
}
endEditMode(): void {
if (this.noteItem.title.trim().length > 4 && this.noteItem.text.trim().length > 4) {
this.editMode = false;
const updatedItem: NewNoteInterface = {
index: this.itemIndex,
newItem: this.noteItem
};
this.updateItem.emit(updatedItem);
}
}
}
package.json
{
"name": "ng-notepad-app",
"version": "0.0.0",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
"private": true,
"dependencies": {
"@angular/animations": "~11.2.5",
"@angular/cdk": "^11.2.13",
"@angular/common": "~11.2.5",
"@angular/compiler": "~11.2.5",
"@angular/core": "~11.2.5",
"@angular/forms": "~11.2.5",
"@angular/localize": "~11.2.5",
"@angular/material": "^11.2.13",
"@angular/platform-browser": "~11.2.5",
"@angular/platform-browser-dynamic": "~11.2.5",
"@angular/router": "~11.2.5",
"@ng-bootstrap/ng-bootstrap": "^9.1.3",
"bootstrap": "^4.5.0",
"rxjs": "~6.6.0",
"tslib": "^2.0.0",
"zone.js": "~0.11.3"
},
"devDependencies": {
"@angular-devkit/build-angular": "~0.1102.3",
"@angular/cli": "~11.2.4",
"@angular/compiler-cli": "~11.2.5",
"@types/jasmine": "~3.6.0",
"@types/node": "^12.11.1",
"codelyzer": "^6.0.0",
"jasmine-core": "~3.6.0",
"jasmine-spec-reporter": "~5.0.0",
"karma": "~6.1.0",
"karma-chrome-launcher": "~3.1.0",
"karma-coverage": "~2.0.3",
"karma-jasmine": "~4.0.0",
"karma-jasmine-html-reporter": "^1.5.0",
"protractor": "~7.0.0",
"ts-node": "~8.3.0",
"tslint": "~6.1.0",
"typescript": "~4.1.5"
}
}
Output:
Add note