2017-10-18 12 views
0

resultに保存されている値に基づいてhtmlファイルのボタンを表示するにはどうすればいいですか?さまざまな値に応じてボタンを表示する方法

page1.ts

class page1 { 
    let result: string; //possible values of result can be 'additon', 
         //'multiply','divide'. 

    constructor(public serviceClass : ServiceClass){ 
    this.initialzie(); 
    } 

    additon(){ 
     this.result = 'addition'; 
    } 

    modulus(){ 
    //logic for this function. 
    } 

    initialize(){ 
    this.result = this.serviceClass.someFunction(); 
    } 
    } 

page1.html

//headers and title already implemented. 

// buttons to implement now. 
//**condition**: The below button is only shown on the basis of the value 
        //populated in the result variable in .ts class. 

<div> //if result = 'multiply, 'divide' then show this button.How to 
        //implement this? 
<button ion-button (click)="addition()">ADD ME</button> 
</div> 

<div> //if result = 'addition' then show this button.How to implement this? 
<button ion-button (click)="modulus()">Modulus</button> 
</div> 

答えて

1

私は、結果の値が取得MEに追加]ボタンをクリックしたときには、 `*ngIf

<div *ngIf="result == 'multiply' || result == 'divide' "> 
<button ion-button (click)="addition()">ADD ME</button> 
</div> 


<div *ngIf="result == 'addition'"> 
<button ion-button (click)="modulus()">Modulus</button> 
</div> 
+0

を使用することができます追加 'ボタン'Modulus'で置き換えられません – Aditya

+0

あなたの追加関数 –

+0

はどこかで' result = addition'の値を更新するので、値が 'addition'に変わると、ボタンは' Modulus 'これは私が実装する必要があるロジックです。 – Aditya

関連する問題