簡體   English   中英

無法將數據從一個模塊組件發送到另一模塊組件

[英]not able to send the data from one module component to another module component

我想將boolean值發送給另一個模塊組件,在該組件中,我應將*ngIf值設置為true以啟用html內容。 它正在導航到另一個組件,但無法啟用html內容。 我已經嘗試過使用viewchild,發射極,輸入,輸出,但是無法達到預期的效果。

調用組件:

SuccessGet(res) {
    this.logs = res;

    for(let item of this.logs)
    {
        if(item._email == this.log._email && item._password == this.log._password)
        {
            alert("Login Successful");

            this.wt.LoginCall(true);     // here calling the other module component
        }
    }

    this.log = new LoginModel();
}

調用的組件:

export class WeatherComponent {
      title = 'TemperatureApp';

      //@Input() messagetochild_weather ;//to get the message from parent

      showweather : boolean = false;
      // showweather : boolean = false;

      bus : BusinessLogic = new BusinessLogic();
      WeatherModel : Weather = new Weather();
      WeatherModels : Array<Weather> = new Array<Weather>();
      num : number = 0;

      LoginCall(item : boolean) 
      {
          //this.ngAfterViewInit();
          this.showweather = item;
      }

      ngAfterViewInit(item : any): void
      {
          this.WeatherModels = this.bus.Load(); 
      }

HTML:

<div *ngIf=showweather class="card">//here i am using *ngIf
  <h3 class="card-header text-center font-weight-bold text-uppercase py-4">Editable table</h3>
  <div class="card-body">
    <div id="table" class="table-editable">
      <span class="table-add float-right mb-3 mr-2"><a href="#!" class="text-success"><i class="fa fa-plus fa-2x"
            aria-hidden="true"></i></a></span>
      <table class=" table table-bordered table-responsive-md table-striped text-center table-responsive-sm" style="border-block-end-color:dodgerblue">
        <tr style="background-color: rgb(0, 255, 255)">
          <th class="text-center">Area Code</th>
          <th class="text-center" >Date</th>
          <th class="text-center">Country</th>
          <th class="text-center">State</th>
          <th class="text-center">City</th>
          <th class="text-center">Temperature</th>
          <th class="text-center">Action</th>
          <th class="text-center">Action</th>
        </tr>

您應該使用Subject / BehaviorSubject。

服務:

private statusValue = new Subject<Boolean>();
statusValue$ = this.statusValue.asObservable();

updateStatus(status){
  this.statusValue.next(status);
}

組件1:

this.service.updateStatus(true);

COMPONENT2:

this.service.statusValue$.subscribe(value=>{console.log(value);}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM