2017-08-16 3 views
1

角度2を使用しています。ドロップダウンの選択に基づいてテーブルを作成しました。ボタンのクリック(行のクローン作成)で新しい行を生成できます。前の行を無効にするにはどうしたらいいですか?値は現在の新しい生成された行だけで変更されます。私はこれを達成することができますどのような選択肢もwelcome.thanksです。 Screenshot角度2の行を無効にする

import { NgModule }  from '@angular/core'; 
 
import { Component, OnInit } from '@angular/core'; 
 
import {SelectItem} from 'primeng/primeng'; 
 
import { FormsModule } from '@angular/forms'; 
 
import {ButtonModule} from 'primeng/primeng'; 
 
import {DataTableModule,SharedModule} from 'primeng/primeng'; 
 

 
@Component({ 
 
    selector: 'app-test', 
 
    templateUrl: 'app/test/test.component.html', 
 
    styleUrls: ['app/test/test.component.css'] 
 
}) 
 
export class TestComponent implements OnInit { 
 

 
makes: SelectItem[]; 
 
selectedMake: string; 
 

 
motors: SelectItem[]; 
 
selectedMotorType: string; 
 

 
poles: SelectItem[]; 
 
selectedPole: string; 
 

 
} 
 

 
constructor() { 
 

 
    this.makes = []; 
 
    this.makes.push({label:'Select makes', value:null}); 
 
    this.makes.push({label:'Siemens', value:{id:1, name: 'Siemens', code: 'Siemens'}}); 
 
    this.makes.push({label:'ABS', value:{id:2, name: 'ABS', code: 'ABS'}}); 
 

 
    this.motors = []; 
 
    this.motors.push({label:'Select Motor Type', value:null}); 
 
    this.motors.push({label:'IE1', value:{id:11, name: 'IE1', code: 'IE1'}}); 
 
    this.motors.push({label:'IE2', value:{id:12, name: 'IE2', code: 'IE2'}}); 
 
    this.motors.push({label:'IE3', value:{id:13, name: 'IE3', code: 'IE3'}}); 
 

 
    this.poles = []; 
 
    this.poles.push({label:'Select Pole Type', value:null}); 
 
    this.poles.push({label:'2 Pole', value:{id:21, name: '2Pole', code: '2Pole'}}); 
 
    this.poles.push({label:'4 Pole', value:{id:22, name: '4Pole', code: '4Pole'}}); 
 
    this.poles.push({label:'6 Pole', value:{id:23, name: '6Pole', code: '6Pole'}}); 
 
} 
 

 

 
//code for button click new row generate 
 
    rows = [{name: ''}]; 
 
    name = "new"; 
 
    addRow() { 
 
    this.rows.push({name: this.name}); 
 
    } 
 
//================= 
 

 
    private textValue = "initial value"; 
 
     private log: string ='result'; 
 
     private kw: string = 'kw'; 
 
     private frame: number = 0; 
 

 
DisplayResult(){ 
 
    if(this.selectedMake.name=='ABS' && this.selectedMotorType.name=='IE1'){ 
 
    alert(this.selectedMake.name); 
 
    this.log = 'IABVC5Z' '\n' 
 
    this.kw = 'new' '\n' 
 
    }}
<div class="container row"> 
 
    <div class="col-sm-6"> 
 
    <p class="col-sm-3" >Makes :</p> 
 
    <p-dropdown class="col-sm-4" [options]="makes" [(ngModel)]="selectedMake" [style]="{'width':'200px'}" ></p-dropdown> 
 
    </div> 
 
</div> 
 
<br> 
 

 
<div class="container row"> 
 
    <div class="col-sm-6"> 
 
    <p class="col-sm-3" >Motor Type :</p> 
 
    <p-dropdown class="col-sm-4" [options]="motors" [(ngModel)]="selectedMotorType" [style]="{'width':'200px'}" ></p-dropdown> 
 
    </div> 
 
</div> 
 
<br> 
 

 
<div class="container row"> 
 
    <div class="col-sm-6"> 
 
    <p class="col-sm-3" >Pole Type :</p> 
 
    <p-dropdown class="col-sm-4" [options]="poles" [(ngModel)]="selectedPole" [style]="{'width':'200px'}" ></p-dropdown> 
 
    </div> 
 
</div> 
 

 
<div class="col-sm-4"> 
 
    <button class="" pButton type="button" class="ui-button-danger" (click)="addRow()" label = " Add New Motor"></button> 
 
    <button class="" pButton type="button" (click)="DisplayResult()" label="Display Result"></button> 
 

 
</div> 
 

 

 

 
<table id="t01"> 
 
<tr> 
 
<th>S.No.</th> 
 
<th>Qty</th> 
 
<th>Type Refrence</th> 
 
<th>KW Rating</th> 
 
<th>Frame Size</th> 
 
<th>Voltage</th> 
 
<th>Frequency</th> 
 
<th>Features</th> 
 
</tr> 
 
<tr *ngFor=" let row of rows"> 
 
<td>1</td> 
 
<td><input type="qty" name="qty"></td> 
 
<td>{{log}}</td> 
 
<td>{{kw}}</td> 
 
<td>{{frame}}</td> 
 
<td>415 v</td> 
 
<td>50 Hz</td> 
 
<td></td> 
 
</tr> 
 
</table>

+0

ここで問題を理解するのが少し難しいですが、もう少し説明してみることができますか? – Alex

+0

@ ajt_82この質問は、私が解決しようとしていたものとは異なるものです。私はテーブルに新しい行を追加したかったのです(新しいMotorボタンをクリックするだけで、問題のスクリーンショットを参照することができます)。私はインデックスを使って新しい行を生成することができます。私はどのように私は新しい生成された行のデータをプッシュすることができます(ショー結果のクリックで、結果のボタンが最初の行のデータを表示することができた)前の行はunchanged.everytime新しいモータ、データショーをクリックする必要があります新しい行に表示されます。 ts code https://pastebin.com/zCL6qYRs、html code https://pastebin.com/Ywv3KJxP –

+0

私は今あなたの問題を得ると思います。あなたは "フォーム"(実際にフォームにすることができます)からオブジェクトを作成し、それらのオブジェクトを配列にプッシュする必要があります。例えば、オブジェクトはプロパティ 'log'を持つので、この場合、すべての' log'は一意です。これで、テーブル内のすべてのフィールドが同じ値を持つことを意味する1つのプロパティ 'log'を使用しています。 – Alex

答えて

0

、その後のことができますクリックイベントで

[disabled]="!available" 

または全タグと

<button type="submit" [disabled]="!available">Submit</button> 

を示すようにタグ内のdisabledプロパティを使用してみてください変数をtrueまたはtにするoそれをトグルする

関連する問題