Advertisement
Guest User

Untitled

a guest
Jun 29th, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.98 KB | None | 0 0
  1. import { Component } from '@angular/core';
  2. import { NavController, AlertController } from 'ionic-angular';
  3. import { AccPvdProvider } from '../../providers/acc-pvd/acc-pvd'
  4. import { GoPage } from '../go/go';
  5.  
  6.  
  7. @Component({
  8. selector: 'page-home',
  9. templateUrl: 'home.html',
  10. providers: [AccPvdProvider]
  11. })
  12. export class HomePage {
  13.  
  14. constructor(
  15. public navCtrl: NavController,
  16. public accpvd : AccPvdProvider,
  17. public alert: AlertController ) {
  18.  
  19. }
  20.  
  21. accounts:number[][];
  22. data:any
  23. acc: string;
  24. pass: string;
  25.  
  26. Login(){
  27.  
  28. let alertlogin = this.alert.create({
  29. title: 'Failed',
  30. buttons:['Try again']
  31. });
  32. this.accpvd.login({
  33. 'acc': this.acc,
  34. 'pass': this.pass
  35. }).subscribe(data =>{
  36.  
  37. let dataa = {
  38. 'body': data
  39. }
  40. if(data.length == 0) alertlogin.present();
  41. else this.navCtrl.push(GoPage, dataa);
  42. });
  43. }
  44.  
  45.  
  46. GetAll(){
  47. var arr = [[],[]];
  48. this.accpvd.getall().subscribe(data => {
  49. console.log(data);
  50. var i,j;
  51. for(i in data){
  52. arr[i] = Object.keys(data[i]).map(function (key) { return data[i][key]; });
  53. }
  54. });
  55.  
  56. this.accounts = arr;
  57. }
  58.  
  59. Create(){
  60.  
  61.  
  62. this.accpvd.createnew({
  63. "acc":this.acc,
  64. "pass":this.pass
  65. }).subscribe(data => {
  66. console.log(data);
  67. });
  68. let alert1 = this.alert.create({
  69. title: 'Welcome!',
  70. buttons:['OK']
  71. });
  72. alert1.present();
  73. }
  74.  
  75. Delete(id){
  76. //document.write(id);
  77. this.accpvd.deleteone(id).subscribe(data => {
  78. console.log(data);
  79. });
  80. let alert2 = this.alert.create({
  81. title: 'Done',
  82. buttons:['OK']
  83. })
  84. alert2.present();
  85. this.GetAll();
  86. }
  87.  
  88. Edit(){
  89. this.accpvd.updateone({
  90. "acc":this.acc,
  91. "pass":this.pass
  92. }).subscribe(data => {
  93. console.log(data);
  94. });
  95. let alert3 = this.alert.create({
  96. title: 'Updated!',
  97. buttons:['OK']
  98. });
  99. alert3.present();
  100. this.GetAll();
  101. }
  102.  
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement