2017-12-15 2 views
1

안녕하세요, 소재 대화 상자에 개체의 배열을 전달하려고합니다. 여기 내가 어떻게하는지. 구성 요소 클래스에서 각도 4 재질 대화 상자가 개체 배열에서 대화 상자로 전달

Model 
export interface IPoducts{ 
    recordname: string; 
    comments: [{ 
     comment: string 
     }] 
} 

관련

 constructor(public dialog: MdDialog, private productService: ProductService){} 
     prod: IProducts[]=[] 
     ngOnInit(): void{ 
    //service getting data from database  

this.productService.getProcessnotes().subscribe(producsts=>this.products=products,error=>this.errorMessage=<any>error); 

     //opening dialgue 
     openDialog(prod:any): void { 
      let dialogRef = this.dialog.open(prodDialog, { 
       width: '400px', 
       height: '500px;', 
      data: this.prod <------------------passing the object array 
       }); 
      }} 

대화 상자 구성 요소를 다음있다.

@Component({ 
     selector: proddialog', 
     templateUrl: 'dialogdetails.html', 
    }) 
    export class ProdDialog implements OnInit{ 
      public pnote: IProducts[]; 
      constructor(
      public dialogRef: MdDialogRef<DialogOverviewExampleDialog>, 
     @Inject(MD_DIALOG_DATA) public data: {pnote:this.prod }) { } 
     public pnote: products; 
      onNoClick(): void { 
      this.dialogRef.close(); 
      } 
      public ngOnInit():void{ 
       this.pnote=this.data.prod; 

      } 

In main template button triggers the dialog box by passing a pnote from *ngFor="let pnote of products" 

<button md-raised-button (click)="openDialog(pnote)">Open Dialog</button> 

대화 상자가 나는이 대화 상자가 튀어 실행하면

<div> 
    <h2 md-dialog-title>MY DIALOG</h2> 
    <hr> 
    <md-dialog-content> 
     <div*ngFor=prod in products> 
      {{prod.recorname}} 
     </div> 
    <br> 
    <br> 
    <strong>{{data}}</strong> 
    </md-dialog-content> 
    <hr> 
    <md-dialog-actions> 
    <button md-raised-button (click)="onCloseConfirm()">CONFIRM</button>&nbsp; 
    <button md-raised-button (click)="onCloseCancel()">CANCEL</button> 
    </md-dialog-actions> 
</div> 

하지만 데이터를 단지 은행을 볼 수있다. Noe 데이터. 대화 상자에 객체의 배열을 전달하는 방법을 알려주시겠습니까? 내 솔루션은 다른 솔루션을 기반으로하지만 여기에는 운이 없습니다.

참고 : 모든 것이 잘 작동합니다. 개체 배열이 전달되는 것 외에는 오류가 없습니다.

+0

어떻게 든 들여 쓰기를 다시 방문 할 수 : 그래서 당신은 openDialogprod에 합격하거나, 다음 this.prod의 방법에서 매개 변수를 할당해야 하나? 두 번째 발췌 문장은 읽기에는 너무 기괴합니다. –

+0

그냥 도움이되기를 바랍니다. 주요 문제는 데이터입니다 : this.prod some 대화 상자로 전달되지 않는 방법 –

답변

0

this.prod에 대한 값을 설정하지 않으므로 값이 없습니다.

openDialog(prod:any): void { 
    this.prod = prod; // here!! 
    let dialogRef = this.dialog.open(prodDialog, { 
    width: '400px', 
    height: '500px;', 
    data: this.prod // now 'this.prod' will have values! 
    }); 
} 
관련 문제