0

我在 angular7 中创建了一个网站,我们在其中将函数从 1 个组件触发到另一个组件函数正常触发,但值未反映在下面的 html 中,我们共享了更新的小提琴:

//Component1. 


import { Component, OnInit } from '@angular/core';
import { Router,NavigationExtras } from "@angular/router";
import {UserService} from "../../service/user.service";
import { FormGroup, FormBuilder, FormControl, FormGroupDirective, NgForm, Validators } from '@angular/forms';
import { DashboardComponent } from '../../dashboard/dashboard.component';


declare var $: any;
@Component({
  selector: 'app-innerheader',
  templateUrl: './innerheader.component.html',
  styleUrls: ['./innerheader.component.css'],
  providers :  [DashboardComponent]
})
export class InnerheaderComponent implements OnInit {
    
  //declare global varible here....  
  private loggedUserObject  : any = {};
  private userImageUrl      : any;

    constructor(
      private router  : Router,
      private service   : UserService,
      private formBuilder: FormBuilder,
      private dashboard : DashboardComponent) {
    }
 
    ngOnInit() {
     
    }

   
     //unblockUser for unblock user
     unblockUser(user : any) {
     
        //pass the dataparam in the backend....
        var data = {
          "user_id"       : this.loggedUserObject.user_id,
          "block_user_id" : this.selectedUser.id
        }
  
        //here we will set url via key wise....
        var url =  '/api/un-block-user-profile';
      
        //saveDetail function for save data in db...
        this.service.saveDetail(data, url).subscribe( (data : any) => {
          if(data.status) {
            
            $('#BlockedListModal').on('hidden.bs.modal', function () {
              this.dashboard.getUserDetail();
            })

            //her we will remove user from the updated list of block user...
            var index = this.blockUserlist.findIndex(x=>x.id == this.selectedUser.id);
            if(index != -1) {
              this.blockUserlist.splice(index, 1);
            }

            //remoive card after accept 
            this.currentElement.remove();
            this.service.successAlert(data.message);
          } 
        });
      
    }
}


//header compeonet 2: here we will fire function from another compeonet
getDashboardDetail() {

  //hold user info
  var data  = {
    "user_id"	     : this.currentUserObject.user_id
  } 
  var url = '/api/time-line-list';

  //createUser function for create user in DB
  this.service.saveDetail(data, url).subscribe( (data : any) => {
  if(data.status) {
      if(data.result.article_info.length >0) {

        if(this.dashboardArticleList.length == 0) {
          this.dashboardArticleList = data.result.article_info;
        } else {
          this.dashboardArticleList  = this.dashboardArticleList.concat(data.result.article_info);
        }
      }
    }
  });
}

//在第二个组件中,我们在模型中显示列表。我在关闭模型后重新加载列表。请检查并告诉我我的代码有什么问题?

4

0 回答 0