FSD-II (Student_angular)Slip

 Create Angular 13application that print the name of students who got 85% using filter and map method.

app.component.ts


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

interface Student {
  name: string;
  percentage: number;
}

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit {
  students: Student[] = [
    { name: 'Ram', percentage: 90 },
    { name: 'Sunil', percentage: 85 },
    { name: 'Suresh', percentage: 82 },
    { name: 'Mona', percentage: 85 },
    { name: 'Sona', percentage: 78 },
  ];

  studentsWith85: string[] = [];

  ngOnInit(): void {
    this.studentsWith85 = this.students
      // filter those whose percentage is exactly 85
      .filter(s => s.percentage === 85)
      // then map to just the names
      .map(s => s.name);
  }
}



app.component.html
<h2>Students who got 85%</h2>
<ul>
  <li *ngFor="let name of studentsWith85">{{ name }}</li>
</ul>







output-
ng serve -o




Comments

Popular posts from this blog

Slip 11: Write node js application that transfer a file as an attachment on web and enables browser to prompt the user to download file using express js.

Slip 7 Create a node js file named main.js for event-driven application. There should be a main loop that listens for events, and then triggers a callback function when one of those events is detected.

Slip 1(a) Write an Angular 13 application addition of two numbers using ng-init, ng-model & ng-bind. And also demonstrate ng-show, ng-disabled, ng-click directives on button component.