-1
limit-Component.ts
import { Component, OnInit, EventEmitter } from '@angular/core';
import { CalculoService } from './calculo.service';
import { Dados } from './dados';
@Component({
selector: 'app-limite-cliente',
templateUrl: './limite-cliente.component.html',
styleUrls: ['./limite-cliente.component.css']
})
export class LimiteClienteComponent implements OnInit {
calculoService: CalculoService;
private dados: Dados = new Dados();
constructor(_calculoService: CalculoService) {
this.calculoService = _calculoService;
}
pegadado() {
console.log(this.dados)
console.log(this.calculoService)
}
ngOnInit() {
}
}
ts.
export class Dados{
pago: number;
emprestimo: number;
devendo: number;
Disponivel: number;
}
calculo.service.ts
import { Injectable, EventEmitter } from '@angular/core';
import {Dados} from './dados'
@Injectable({
providedIn: 'root'
})
export class CalculoService {
emprestimo:number;
pago:number;
devendo:number;
Disponivel:number;
//mostrarGraficoEmitter = new EventEmitter<boolean>(false);
pegadado(dados:Dados) {
this.emprestimo = dados.emprestimo;
this.pago = dados.pago;
this.devendo = this.emprestimo - this.pago;
this.Disponivel = 3500 - (this.pago + this.devendo);
if (this.devendo == 0) {
this.pago = 0
this.Disponivel = 3500
}
return [this.emprestimo,this.pago,this.Disponivel,this.devendo];
}
}
html client limit.
<div class="main-content">
<div class="panel-row">
<div class="painel-butao">
<div class="painel-emprestimo">
<label for="emprestimo">Emprestimo</label>
<input [(ngModel)]="dados.emprestimo" id="emprestimo" type="number"
placeholder="Digite quanto foi emprestado">
<label for="pago"> pago</label>
<input [(ngModel)]="dados.pago" id="pago" type="number" placeholder="Digite quanto foi pago">
</div>
<button type="submit" name="action" (click)="pegadado()" >calcular</button>
</div>
The service footprint function is not being called and I am not being able to print the value on the console.
It was not clear your question, it seems to be all right, maybe you are making confusion in the function footprint of the archive
calculo.service
with the file functionlimite.component
.– LeAndrade
because, but at the time of printing the function with the console the function of the calculation.service does not run (for example if put values before the function they are printed) and in case it was to run the two functions.
– RoliXit
But the service will never run at all, you’re not running it anywhere.
– LeAndrade