2017-02-01 3 views
-1

{{buttonText}}の動的値を設定する方法は誰でも知っていますか?htmlの補間用テキストを設定する

これ以上表示する記事がない場合は、{{buttonText}}が「表示が少ない」と表示されるようにしたいと考えています。

マイHtmlの

<button ion-item (click)="items.showMore2 = !items.showMore2; items.showMore1 = !items.showMore1; items.toggleMore2 = !items.toggleMore2; items.toggleMore1 = !items.toggleMore1" [hidden]="items.toggleMore1" text-center detail-none large> 
    <h4 class="showMoreText"><ion-icon name="arrow-down" *ngIf="!items.arrow"></ion-icon> 
    <ion-icon name="arrow-up" *ngIf="items.arrow"></ion-icon> {{buttonText}}</h4> 
</button> 

すべてのヘルプは歓迎です!

+0

あなたはコンポーネントの右内側に値を代入知っていますか?あなたの質問は少し不明です – echonax

答えて

1

最初は、angular.io補間のガイドを参照することをお勧めします。これは実際には角度の基本であるためです。そのウェブサイトにダイビングをしてガイドと料理本を読んで、角度の基礎を掴んでください。

あなたの@Componentクラス内の変数を設定することができます。

@Component({ 
    template: `<div>{{buttonText}}</div> 
}) 
export class AppComponent { 

    public buttonText: string = "test"; 

} 

あなたのコンポーネント内に定義された任意の変数/メソッドは、テンプレート内の変数を変更して、テンプレート内

+0

こんにちはしかし、私は動的な変更のテキストをしようとしているので、typescriptの代わりにhtmlの文字列値を割り当てる方法があります。 –

+0

あなたが達成しようとしていることについてあなたの質問に大きな例を作りましょう – PierreDuc

1
{{buttonText}} 

export class App{ 
    buttonText:string="test"; 
} 
0

をある使用することができます可能ですが、あなたはそれのためにどんなイベントも必要とします。

<div> 
    <h2 (click)="name = 'test'">Hello {{name}}</h2> <!-- simple --> 
    <h2 (click)="name = names[(index = ((index + 1) % names.length))]">Hello {{name}}</h2> <!-- expert --> 
</div> 

ライブデモ:https://plnkr.co/edit/SePBxTOvOKlSE2gQ8Xi2?p=preview

関連する問題