2017-05-05 93 views
1

我有这段代码来迭代stacklist_table这是一个json数组中的数据并以表格格式显示它。 stacklist_table是所有对象的完整列表。但我不需要所有的对象,所以我应用了一些管道。然后我的最终值保存在#stacklist下面,它反复显示列和行。在ts文件中获取mfData值以在角度上执行操作2

<table class="table" [mfData]="stacklist_table| selectedcolumn | search : searchQuery | filter: addFilter : selected" #stacklist="mfDataTable"> 
       <thead> 
       <tr> 
        <th *ngFor="let colValues of stacklist.data | column: '' : ''"> 
        <mfDefaultSorter by="{{colValues}}">{{colValues|translate}}</mfDefaultSorter> 
        </th> 
       </tr> 
       </thead> 
       <tbody> 
       <tr draggable *ngFor="let stack of stacklist.data" [dragOverClass]="'drag-over-border'" [dragData]="stack" [class.active]="checkIfStackElementIsSelected(stack)" (click)="setStacklistRow(stack)"> 
        <td *ngFor="let rowValues of stack | row">{{ rowValues }}</td> 
       </tr> 
       </tbody> 
      </table> 

我可以在我的后端typescript文件中访问这个#stacklist值吗? 我需要在打字稿文件中应用了所有管道后的最终堆叠列表。我怎么去解决它?

+0

如果你需要'@ Pipe'应用这个数据,你也可以在你的'component.ts'中应用你的管道 – SrAxi

回答

1

如果您想要在component.ts中应用管道后访问数据,则可以直接在组件中应用管道。

import { MyCustomPipe } from './my-custom.pipe'; 

export class MyClass { 
    constructor(private customPipe: MyCustomPipe){ 
    this.pipeAppliedData = this.customPipe.transform(someData); // this will be like doing in template "someData | MyCustomPipe" 
    }  
} 

在这一点上,你可以做任何你需要做的与管你的数据应用(this.pipeAppliedData),然后在模板中使用this.pipeAppliedData。这样你就可以使用管道一次(在你的组件中),并且你可以在两边使用结果:模板和组件。

+0

就像在相同的列表上应用两次管道一样。那是档案吗? –

+1

那么,如果您需要将其用于其他内容,则可以将其应用于组件中,然后可以将结果数据用于模板中。如果您不需要组件中应用管道的数据,则只需按照预期使用管道:在模板中。我给你的是在组件内部使用管道的解决方案,我认为这是你想要/需要的。 :D – SrAxi

+0

@MendonAshwini我更新了我的答案,看看! ;)希望它有助于队友! ;) – SrAxi

相关问题