-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcompany.service.ts
94 lines (77 loc) · 2.49 KB
/
company.service.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import { Injectable } from '@angular/core';
import { Component, OnInit, Input } from '@angular/core';
import { AngularFireDatabase, FirebaseListObservable } from 'angularfire2/database';
import { Router } from '@angular/router';
import { FormBuilder, FormControl, FormGroup, Validators, ReactiveFormsModule } from '@angular/forms';
import { AngularFireAuth } from 'angularfire2/auth';
import { CompanyComponent } from './company/company.component';
@Injectable()
export class CompanyService {
addPosts: FirebaseListObservable<any[]>;
offer: FirebaseListObservable<any[]>;
constructor(public cc: CompanyComponent, public db: AngularFireDatabase, public af: AngularFireAuth) {
this.offer = db.list("/offer");
this.addPosts = db.list("/addposts" + this.uid);
}
ex = this.cc.cdetails;
uid;
post
description;
name;
password;
// submit() {
// this.uid = this.af.auth.currentUser.uid;
// this.cdetails = this.db.list('/compdetails/' + this.uid, { preserveSnapshot: true });
// this.cdetails
// .subscribe(snapshots => {
// snapshots.forEach(snapshot => {
// console.log(snapshot.val())
// })
// });
// }
addPost(post: String, description: String) {
this.uid = this.af.auth.currentUser.uid;
let formdata = { post, description }
this.db.list("/addposts/" + this.uid).push(formdata);
}
get demo(): any {
this.viewPost();
return this.array;
}
array = [];
viewPost() {
this.uid = this.af.auth.currentUser.uid;
this.addPosts = this.db.list('/addposts/' + this.uid, { preserveSnapshot: true });
this.addPosts
.subscribe(snapshots => {
snapshots.forEach(snapshot => {
console.log(snapshot.key)
console.log(snapshot.val())
this.array.push(snapshot.val())
console.log(this.array);
});
})
}
// get demoo(): any {
// this.viewcomp();
// return this.arry;
// }
// arry = [];
// comp: FirebaseListObservable<any[]>;
// viewcomp() {
// // this.uid = this.af.auth.currentUser.uid;
// this.comp = this.db.list('/compdetails', { preserveSnapshot: true });
// this.comp
// .subscribe(snapshots => {
// this.arry = [];
// snapshots.forEach(snapshot => {
// snapshot.forEach(child => {
// console.log(child.key)
// console.log(child.val())
// this.arry.push(child.val())
// console.log(this.arry);
// })
// });
// })
// }
}