2017-12-28 40 views
-1

View of the pagetrタグ内の2つのngForループの使い方は?

私はビューの画像を添付しました。私は、trタグ内の2つのngforループを繰り返したいと思う。 trの中にdivタグを使用しましたが、タグの隣にあるボタンをループしています。私はそれをファイルテーブルのヘッダに入れます(理解のために画像ファイルを参照してください)...

テーブルセクション: これは私のHTMLページのテーブルセクションです。

<table class="table"> 
          <thead> 
           <tr> 
            <th scope="col">Category</th> 
            <th scope="col">Created By</th> 
            <th scope="col">Date Created</th> 
            <th scope="col">File Name</th> 
            <th scope="col">File</th> 
           </tr> 
          </thead> 
          <tbody> 
           <ng-template [ngTemplateOutlet]="tmplt"></ng-template> 
          </tbody> 

         </table> 
         <input class="btn btn-primary" type="button" value="Save" /> 
         <input class="btn btn-danger" type="button" value="Cancel" /> 
        </form> 
       </div> 
      </div> 
     </div> 
     <ng-template #tmplt> 

      <tr *ngFor="let cattype of categorytype"> 
       <td>{{cattype.Name}}</td> 
       <div *ngFor="let manage of managecontent"> 
        <td>{{manage.CreatedBy}}</td> 
        <td>{{manage.CreatedDate}}</td> 
        <td>{{manage.DocumentDetails.DocName}}</td> 
        <td><app-file-upload [documentModel]="manage.DocumentDetails" [isMultipleFile]="true" [model]="manage" (emitterFile)="fileSelect($event)"></app-file-upload></td> 
        <td><input class="btn btn-danger" type="button" value="Remove" /></td> 
       </div> 
      </tr> 

     </ng-template> 

完全なHTMLテンプレート:

<div class="text-center"> 
     <div class="container"> 
      <div class="jumbotron"> 
       <form novalidate> 
        <h3>Manage Content</h3> 
        <br> 
        <h4>Select Gender:</h4> 
        <label class="radio-inline"><input type="radio" #gender name="gender" value="1" checked>Male</label> 
        <label class="radio-inline"><input type="radio" #gender name="gender" value="2">Female</label> 
        <br> 
        <br> 
        <h4>Select Routing Type:</h4> 
        <div class="row"> 
         <div class="col-sm-3"></div> 
         <div class="col-sm-6"> 
          <select class="form-control">  
           <option>Choose Route Type</option> 
           <option *ngFor="let manage of dropdown" value="{{manage.Id}}">{{manage.Name}}</option> 
          </select> 
         </div> 
        </div> 
        <br> 
        <br> 
        <table class="table"> 
         <thead> 
          <tr> 
           <th scope="col">Category</th> 
           <th scope="col">Created By</th> 
           <th scope="col">Date Created</th> 
           <th scope="col">File Name</th> 
           <th scope="col">File</th> 
          </tr> 
         </thead> 
         <tbody> 
          <ng-template [ngTemplateOutlet]="tmplt"></ng-template> 
         </tbody> 

        </table> 
        <input class="btn btn-primary" type="button" value="Save" /> 
        <input class="btn btn-danger" type="button" value="Cancel" /> 
       </form> 
      </div> 
     </div> 
    </div> 
    <ng-template #tmplt> 

     <tr *ngFor="let cattype of categorytype"> 
      <td>{{cattype.Name}}</td> 
      <div *ngFor="let manage of managecontent"> 
       <td>{{manage.CreatedBy}}</td> 
       <td>{{manage.CreatedDate}}</td> 
       <td>{{manage.DocumentDetails.DocName}}</td> 
       <td><app-file-upload [documentModel]="manage.DocumentDetails" [isMultipleFile]="true" [model]="manage" (emitterFile)="fileSelect($event)"></app-file-upload></td> 
       <td><input class="btn btn-danger" type="button" value="Remove" /></td> 
      </div> 
     </tr> 

    </ng-template> 

TSファイル:

import { Component, OnInit, TemplateRef, ViewChild } from "@angular/core"; 
import { ManageContentService } from "../Service/managecontent.service"; 
import { ManageContentModel, dropdownmodel, categorytypemodel } from "../Model/managecontent.model"; 
import { DocumentDetails } from "../Model/document.model"; 




@Component({ 
    selector: 'manage-content', 
    templateUrl: './app/QadAdminConfig/Templates/managecontent.component.html', 
    providers: [ManageContentService] 
}) 


export class ManageContentComponent implements OnInit { 

    data: any; 
    categorytype: Array<categorytypemodel> = []; 
    dropdown: Array<dropdownmodel> = []; 
    managecontent: Array<ManageContentModel> = []; 

    @ViewChild("tmplt") tmpltTbl: TemplateRef<any>; 



    ngOnInit() 
    { 
     this.getRouType(); 
     this.getcontenttype(); 

    } 

    constructor(private _managecontentService: ManageContentService) 
    { 
     let model: ManageContentModel = new ManageContentModel(); 
     model.DocumentDetails = new DocumentDetails(); 
     model.DocumentDetails.Id = 0; 
     this.managecontent.push(model); 
    } 


    getRouType() { 
     this._managecontentService.GetRouteType().subscribe(
      data => { 
       if (data.Success) { 
        this.dropdown = data.Result as dropdownmodel[]; 
        console.log(this.dropdown); 
       } 
      }); 
    } 

    getcontenttype() { 
     this._managecontentService.GetContent().subscribe(
      data => { 
       if (data.Success) { 
        this.categorytype = data.Result as categorytypemodel[]; 
        console.log(this.categorytype); 
        console.log(this.managecontent); 
       } 
      }); 
    } 

    getdata() { 

    } 
} 

モデル:

import { BaseModel } from "./base.model"; 
import { DocumentDetails } from "./document.model"; 

export class ManageContentModel extends BaseModel { 

    RouteTypeId: number; 
    CategoryTypeId: number; 
    Gender: number; 
    DocId: number; 
    DocumentDetails: DocumentDetails; 


} 

export class dropdownmodel { 
    Id: number; 
    Name: string; 
    Name_AR: string; 
} 

export class categorytypemodel { 
    Id: number; 
    Name: string; 
    Name_AR: string; 
} 
+0

が –

+0

であなたのNgForを入れてみてくださいあなたは私のコード –

答えて

0

を使用できng-template構文

詳細については、210

https://toddmotto.com/angular-ngfor-template-element#ngfor-and-ng-template

<tr *ngFor="let cattype of categorytype"> 
    <td>{{cattype.Name}}</td> 
    <ng-template ngFor let-manage [ngForOf]="managecontent | async"> 
     <td>{{manage.CreatedBy}}</td> 
     <td>{{manage.CreatedDate}}</td> 
     <td>{{manage.DocumentDetails.DocName}}</td> 
     <td><app-file-upload [documentModel]="manage.DocumentDetails" [isMultipleFile]="true" [model]="manage" (emitterFile)="fileSelect($event)"></app-file-upload></td> 
     <td><input class="btn btn-danger" type="button" value="Remove" /></td> 
    </ng-template> 
</tr> 
+0

InvalidPipeArgumentを提案することができます:「[オブジェクトのオブジェクト]」パイプのための「AsyncPipe」私は –

+0

あなたにこのエラーが出ますあなたのモジュールにパイプをインポートするか、パイプを削除する必要があります。ここをクリックhttps://www.concretepage.com/angular-2/angular-2-async-pipe-example – klonq

+0

まだ私はそのエラーを取得する..私は共通のモジュールをインポート –

関連する問題