2016-11-25 7 views
2

私は、アイテムの詳細を表示するにはng2-bootstrap modal各アイテムの詳細をモーダルng2ブートストラップに渡すにはどうすればよいですか?

を使用しています。それぞれのアイテムをクリックすると、それぞれの詳細がモーダルに表示されます。私は私が唯一、それぞれのユーザーその他の詳細を通過したいそれぞれの行をクリックすると、ここで

は私のコード

<table class="table table-hover table-bordered table-striped tableheader"> 
<thead> 
    <tr> 
    <th>First Name</th> 
    <th>Last Name</th> 
    <th>Gender</th> 
    <th>City</th> 
    <th>Country</th> 
    <th>Age</th> 
    </tr> 
</thead> 
    <tbody *ngFor="let item of results$ | async" > 
    <tr (click)="lgModal.show(item)"> 
     <td> 
     {{item.firstName}} 
     </td> 
     <td>{{item.lastName}}</td> 
     <td>{{item.gender}}</td> 
     <td>{{item.city}}</td> 
     <td>{{item.country}}</td> 
     <td>{{item.age}}</td> 
    </tr> 
    </tbody> 
</table> 

ですが、それは同じであるモーダルに私の結果$の完全なJSONを渡していますコンポーネント

<div bsModal #lgModal="bs-modal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="true"> 
    <div class="modal-dialog modal-lg"> 
    <div class="modal-content"> 
     <div class="modal-header"> 
     <button type="button" class="close" (click)="lgModal.hide()" aria-label="Close"> 
      <span aria-hidden="true">&times;</span> 
     </button> 
     <h4 class="modal-title">Complete Details</h4> 
     </div> 
     <div class="modal-body"> 
     <div > 
      {{ item | json }} // not getting item details here 
     </div> 
     </div> 
    </div> 
    </div> 
</div> 

これをどのように行うには?

+0

のみのパスで

component.htmlで

<tr (click)="onClick(item,lgModal)"> 

それ データインスタンスをモーダルに変換し、モーダルでデータ(結果$)を再度繰り返します。 – Manish

+0

@ user32私はモーダルにデータを渡すことができるように私はカスタム関数を書くことができます –

+0

私は1つのことを教えてくれますか?モーダルHTMLは同じコンポーネント内にあるか、別のコンポーネント内にあります。その場合は、コンポーネント通信のために移動する必要があります。 (@入出力)。 – Manish

答えて

1

これがわかりました。

もう1つの関数を作成し、その関数呼び出しによって必要なデータを渡しました。私component.ts

public selecteditem: Observable<Object>; 

onClick(item:any, lgModal:any){ 

    this.selecteditem = item; 

    lgModal.show() 

    // console.log(this.selecteditem); // print in console 

} 

component.html中)モーダル体

<div class="modal-body"> 

    <pre>{{ selecteditem | json }} </pre> 

     // Example 

     <h5>SChool Name:{{selecteditem?.schoolName}}</h5> 

     </div> 
0

私があなたの質問を理解していれば、それぞれのアイテムIDをあなたのリストUIからモーダルに渡すのを忘れてしまいました。例:
をクリックして、モーダルでクリックしたレコードの詳細を表示するだけです。モーダルについては、その単数のレコードで再度繰り返す必要はありません。

私はこれが正しいとあなたに役立つことを望みます。

+0

私はこの機能にアイテムを渡しました(クリック)= "lgModal.show(アイテム)"それは試していませんでした。私は試しました –

+0

アイテムへのアクセス方法はわかりません。そのデータの参照名をチェックし、それぞれのデータを表示するためにバインディングを使用します。繰り返さないでください。 – Manish

+0

@ user32は参照を渡しましたが、まだ出力はありません –

関連する問題