Иони c 4 получить возвращаемое значение из функции - PullRequest
0 голосов
/ 21 марта 2020

Мне нужно получить значение из функции, которая находится в другом сервисном файле

my service.ts

  createForum(forumDetails) {
    return this.angularFirestore.collection('Forums').add(forumDetails).then(ref => {
      ref.set({ forum_id: ref.id }, { merge: true }).then((data) => {
      console.log(ref.id); // I need this value to return
      console.log("Forum id is added");

      });
  })
}

home.ts

  create() {
  console.log(this.user);
    if(this.Name == ""){
      this.toast.show('Please give a title');
      console.log('empty');
    }
     else
     if(this.description == ""){
      this.toast.show('Please give a body');
      console.log('empty');
    }
    else{
     // the user details are updated in firebase user list
     this.forumDetails = {
       title: this.Name,
       body: this.description || '',
       userName: this.user.username,
       userId: this.user.userId,
       time: new Date(),
       answers: [],
       location: this.user.location,
       vote:JSON.stringify({positive:[],negative:[]})
}
     console.log(this.forumDetails);
  // details are submitted to creatGroup function from groupProvider
      this.messageService.createForum(this.forumDetails).then(resp => {
        console.log(resp); //here i need to see the return value
        this.toast.show("Forum Created");
        this.router.navigate(["/forum"]);

      });
  }
}

Я пытаюсь с return ref.id;, но в home.ts значение не отображается

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...