<file_sep>import { Component, OnInit } from '@angular/core';
import { Injectable } from '@angular/core';
import { Http } from '@angular/http';
import { HttpClient } from '@angular/common/http';


@Component({
  selector: 'app-school-result',
  templateUrl: './school-result.component.html',
  styleUrls: ['./school-result.component.css']
})

export class SchoolResultComponent implements OnInit {
  data;
  studentResults: any;
  studentName: String;
  total = [];
  totalMarks: number;
  students = [];
  max:number =0;
  maxMarks: any;
  
  constructor(private http: HttpClient) {
  }

  getStudentResults() {
    return this.http.get('../assets/data.json')
      .toPromise().then(res => {
        return res
      }
      )
  }
  ngOnInit() {
    this.getStudentResults().then(
      res => {
        this.studentResults = res;
        if (this.studentResults) {
          let result;
          for (let i = 0; i < this.studentResults.length; i++) {
            this.totalMarks = parseInt(this.studentResults[i].marks.English) + parseInt(this.studentResults[i].marks.Maths) + parseInt(this.studentResults[i].marks.Science);
            if (this.totalMarks >this.max) {
              this.max=this.totalMarks;
              this.maxMarks=this.totalMarks;
             } 
            if (this.studentResults[i].marks.English < 20 || this.studentResults[i].marks.Maths < 20 || this.studentResults[i].marks.Science < 20) {
              result = "fail";
            }
            else {
              result = "pass";
            }
            this.students.push({ 'rollNumber': this.studentResults[i].rollNumber, 'total': this.totalMarks, 'result': result, 'student': this.studentResults[i] });
          }
          for (let i = 0; i < this.students.length; i++) {
            if(this.maxMarks == this.students[i].total){
          this.students[i].result = "topper";
            }
          }
          console.log(this.students);
          console.log(this.maxMarks);
          // var sorted = this.students.sort(); 
          // console.log("Returned string is : " + sorted );
          
          
        }
      }

    )

 
  }

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

@Component({
  selector: 'app-school-form',
  templateUrl: './school-form.component.html',
  styleUrls: ['./school-form.component.css']
})
export class SchoolFormComponent implements OnInit {
  firstName: string;
  lastname: string;
  class: string;
percentage: string;
yop: number;
submitBtn :boolean = false;
  constructor() { }


  onKeyUpValidation(){
    if(this.firstName && this.lastname && this.class && this.percentage && this.yop){
      if(this.firstName.length > 1 && this.firstName.length <= 20 && this.lastname.length > 1 && this.lastname.length <= 20 && this.class.length > 1 && this.percentage.length > 1 && this.yop < 2018 && this.yop > 1980){
        this.submitBtn = true;
      }
      else{
        this.submitBtn = false;
      }
    }
  }
  ngOnInit() {
   
  }
 submit(){
    alert("Vaild");
  }
 

}
