Skip to content

Instantly share code, notes, and snippets.

@tajulasri
Last active November 17, 2018 03:05
Show Gist options
  • Save tajulasri/fa8669a4889dccc66eb4895347bb785d to your computer and use it in GitHub Desktop.
Save tajulasri/fa8669a4889dccc66eb4895347bb785d to your computer and use it in GitHub Desktop.
<ion-header>
<ion-navbar>
<ion-title>
Apps Tajul Asri
</ion-title>
</ion-navbar>
</ion-header>
<ion-content padding>
<ion-list>
<ion-item>
<ion-input type="number" text-center [(ngModel)]="formInput.harga" placeholder="Harga"></ion-input>
</ion-item>
<ion-item>
<ion-input type="number" text-center [(ngModel)]="formInput.kuantiti" placeholder="Kuantiti"></ion-input>
</ion-item>
<ion-item>
<ion-input type="number" text-center [(ngModel)]="formInput.diskaun" placeholder="Diskaun"></ion-input>
</ion-item>
</ion-list>
<button ion-button (click)="bilaButtonKiraDiTekan()" full color="danger">Kira</button>
<p>
If you get lost, the <a href="http://ionicframework.com/docs/v2">docs</a> will be your guide.
</p>
</ion-content>
import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { AlertController } from "ionic-angular";
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
//form kita ada 3 attributes
//harga
//kuantiti
//diskaun
//model
formInput = {
harga: 0,
kuantiti: 1,
diskaun: 0
}
constructor(public alertCtrl: AlertController,public navCtrl: NavController) {
}
bilaButtonKiraDiTekan() {
//kita sediakan pemboleh ubah yang berkemungkinan
var hargaProduct = this.formInput.harga;
var kuantiti = this.formInput.kuantiti;
var diskaun = this.formInput.diskaun;
//kita cuba kira discount
var less = diskaun / 100;
//jumlah harga barang tanpa potongan
var hargaAsalBarang = hargaProduct*kuantiti;
//jumlah diskaun potongan bentuk 0/100 kena darab
//dengan harga barang asal
//jumlah pembelian diskaun setiap barang didarab
// dengan bilangan kuantiti
var diskaunKeseluruhan = (less * hargaProduct) * kuantiti;
var hargaSelepasPotongan = hargaAsalBarang - diskaunKeseluruhan;
console.log(hargaSelepasPotongan);
var tukarKepadaFormatHarga = hargaSelepasPotongan.toFixed(2);
const alert = this.alertCtrl.create({
title: 'Keputusan pengiraan',
subTitle: 'RM ' + tukarKepadaFormatHarga,
buttons: ['OK']
});
alert.present();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment