0% found this document useful (0 votes)
5 views8 pages

MPT Micro Project - Removed

The document outlines the code for a Notepad application built with Angular, featuring components for adding, displaying, editing, and deleting notes. Key components include AddBtnComponent for adding notes, ContainerComponent for managing the list of notes, and NoteItemComponent for individual note interactions. The application utilizes Angular Material and Bootstrap for styling and modal functionality.

Uploaded by

Meet Pandav
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views8 pages

MPT Micro Project - Removed

The document outlines the code for a Notepad application built with Angular, featuring components for adding, displaying, editing, and deleting notes. Key components include AddBtnComponent for adding notes, ContainerComponent for managing the list of notes, and NoteItemComponent for individual note interactions. The application utilizes Angular Material and Bootstrap for styling and modal functionality.

Uploaded by

Meet Pandav
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Aim: Develop a Notepad application with functionality of digital Notebook.

Code:
add-btn.component.ts

import {Component, Output, EventEmitter, Input} from '@angular/core';

import {NgbModal, ModalDismissReasons} from '@ng-bootstrap/ng-bootstrap';


import {NoteInterface} from '../AngularNotepadApp-main/src/app/shared/note-interface';

@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();

constructor(private modalService: NgbModal) {


}

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)}`;
});
}

getDismissReason(reason: any): string {


if (reason === ModalDismissReasons.ESC) {
return 'by pressing ESC';
} else if (reason === ModalDismissReasons.BACKDROP_CLICK) {
return 'by clicking on a backdrop';
} else {
return `with: ${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

import {Component} from '@angular/core';

@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';

import { AppComponent } from './app.component';


import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
import { ContainerComponent } from './container.component';
import { NoteItemComponent } from './note-item.component';
import { AddBtnComponent } from './add-btn.component';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import {MatIconModule} from '@angular/material/icon';
import {FormsModule} from '@angular/forms';

@NgModule({
declarations: [
AppComponent,
ContainerComponent,
NoteItemComponent,
AddBtnComponent
],
imports: [
BrowserModule,
NgbModule,
BrowserAnimationsModule,
MatIconModule,
FormsModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }

container.component.ts

import {Component, Input} from '@angular/core';


import {NoteInterface} from '../AngularNotepadApp-main/src/app/shared/note-interface';
import {NewNoteInterface} from '../AngularNotepadApp-main/src/app/shared/new-note-
interface';

@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);
}

onDellItem(itemIndex: number): void {


this.notes.splice(itemIndex, 1);
}

onUpdateItem(item: NewNoteInterface): void {


this.notes.splice(item.index, 1, item.newItem);
}
}
note-item.componenet.ts

import {Component, EventEmitter, Input, Output} from '@angular/core';


import {NoteInterface} from '../shared/note-interface';
import {NewNoteInterface} from '../shared/new-note-interface';

@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

import {Component, EventEmitter, Input, Output} from '@angular/core';


import {NoteInterface} from '../AngularNotepadApp-main/src/app/shared/note-interface';
import {NewNoteInterface} from '../AngularNotepadApp-main/src/app/shared/new-note-
interface';

@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

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy