AngularJS ng-switch
Yönergesi
Örnek
Yalnızca belirli bir değerle eşleşiyorsa, HTML'nin bir bölümünü gösterin:
<div ng-switch="myVar">
<div ng-switch-when="dogs">
<h1>Dogs</h1>
<p>Welcome to a world of dogs.</p>
</div>
<div ng-switch-when="tuts">
<h1>Tutorials</h1>
<p>Learn from examples.</p>
</div>
<div ng-switch-when="cars">
<h1>Cars</h1>
<p>Read about cars.</p>
</div>
<div ng-switch-default>
<h1>Switch</h1>
<p>Select topic from the dropdown, to switch the content of this DIV.</p>
</div>
</div>
Tanım ve Kullanım
Yönerge ng-switch
, bir ifadeye bağlı olarak HTML öğelerini gizlemenize/göstermenize izin verir.
Eşleşirse yönergeye sahip alt öğeler ng-switch-when
görüntülenecektir, aksi takdirde öğe ve alt öğeleri kaldırılacaktır.
ng-switch-default
Diğer bölümlerden hiçbiri eşleşmezse bir bölümü göstermek için yönergeyi kullanarak varsayılan bir bölüm de tanımlayabilirsiniz .
Sözdizimi
<element ng-switch="expression">
<element ng-switch-when="value"></element>
<element ng-switch-when="value"></element>
<element ng-switch-when="value"></element>
<element ng-switch-default></element>
</element>
Tüm HTML öğeleri tarafından desteklenir.
Parametre Değerleri
Value | Description |
---|---|
expression | An expression that will remove elements with no match, and display elements with a match. |