nycJSorg/angular-presentation

View on GitHub
libs/code-demos/src/lib/realtime-eval/realtime-eval.component.ts

Summary

Maintainability
A
0 mins
Test Coverage
import { Component, Input, OnInit } from '@angular/core';

@Component({
  selector: 'code-demo-realtime-eval',
  templateUrl: './realtime-eval.component.html',
  styleUrls: ['./realtime-eval.component.css']
})
export class RealtimeEvalComponent implements OnInit {
  @Input() code = '';
  @Input() language = 'typescript';
  result: string;
  error: string;

  ngOnInit() {}

  evaluate() {
    try {
      this.result = eval(this.code);
      this.error = '';
    } catch (e) {
      this.result = '';
      this.error = e.message;
    }
  }
}