如何将数据模态.ts注入到另一个

问题描述 投票:0回答:1

不确定'inject'是否正确。我对编码还是很陌生,我可以问爸爸跟我一起工作,但是我想尝试解决stackoverflow问题。对不起,如果最终无法理解。

背景:

我正在制作具有弹出对话框的面板表,以将更多面板添加到提案中。该表来自3个不同的数据集proposal.ts,boards.ts,proposal-board.ts数据传输良好,麻烦的是使其显示在表中。

[显示的数据在const proposalBoard = new ProposalBoard( ... )中与proposal-board.ts中的元素绑定在一起,但是EndDate和StartDate元素来自proposal.ts,而不是proposal-board.ts。

所以问题是:我可以将EndDate和StartDate元素注入proposal-board.ts吗?如果可以,怎么办?


edit-proposal.component.html

    <ng2-smart-table [settings]="proposalBoardSettings" [source]="proposal.Boards">
    </ng2-smart-table>

    <div class="col-sm-2">
      <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#add-boards-modal"
        (click)="showBoardSelectDialog">+ Add Boards</button>

      <div *ngIf='proposal.Boards'>
        <app-boardselectdialog (selectedBoards)="addBoards($event)" [boards]="proposal.Boards"></app-boardselectdialog>
      </div>
    </div>  

edit-proposal.component.ts

export class EditProposalComponent implements OnInit {
 boards: any = {};
proposal: any = {};


proposalBoardSettings = {
    actions: false,
    columns: {
      StructureNumber: {
        title: 'StructureNum',
        filter: false
      },
      BoardName: {
        title: 'BoardName',
        filter: false
      },
      StartDate: {
        title: 'Start Date',
        filter: false
      },
      EndDate: {
        title: 'End Date',
        filter: false
      },
      Status: {
        title: 'Status',
        filter: false
      },
      Cost: {
        title: 'Cost',
        filter: false
      },
      Price: {
        title: 'Price',
        filter: false
      }
    }
  };

 addBoards(boards: any) {
    const newProposalBoards: ProposalBoard[] = [];
    boards.forEach(element => {
      // loops through the boards returned from the dialog
      // tslint:disable-next-line: max-line-length
      console.log('Dialog Board', element);
      // creates new ProspoalBoards objects from Boards objects returned from Dialog
      const proposalBoard = new ProposalBoard(
        element.Name,
        element.StructureNumber,
        element.Cost,
        element.EndDate,   //<- these are squigled
        element.StartDate,  //<- these are squigled
      );
      // adds new ProposalBoards to the array
      newProposalBoards.push(proposalBoard);
    });
    console.log('ProposalBoards', newProposalBoards);
    // replace Boards with new array of boards to show on the table
    this.proposal.Boards = newProposalBoards;

    this.UpdateCosts();
    this.UpdatePrice();
    console.log('Proposals');
  }
}

proposal-board.ts

export class ProposalBoard {
         BoardName: string;
         StructureNumber: string;
         Cost: number;

         constructor(name: string, 
                    structureNumber: string, 
                    cost: number, 
                    ) {

          this.StructureNumber = structureNumber;
           this.BoardName = name;
           this.Cost = cost;
         }
       }

proposal.ts

export class Proposal {
    EndDate: string;
    StartDate: string;


    constructor(
        endDate: string,
        startDate: string,
    ) {
        this.EndDate = endDate;
        this.StartDate = startDate;
    }
}
angular angular7
1个回答
0
投票

在调用addBoards的方法时刷新表可能会帮助您

© www.soinside.com 2019 - 2024. All rights reserved.