AngularJsの新機能ですので、ngif
の構文が不明です。私はテーブルを持っており、component.status
の値に応じて<td>
のクラスを変更する必要があります。これまでAngularJs ng-ifディレクティブが機能しない場合
$scope.components =
[
{type: "Dispacther", component: "Dispatcher2", created: "2016-05-20T01:44:56.113", status: "Live"},
{type: "Mobilizer", component: "Mobility3", created: "2016-05-25T07:34:30.019", status: "Down"},
{type: "Listener", component: "ADT 22146", created: "2016-05-20T01:44:56.113", status: "Live"},
{type: "OutBound Charge", component: "Billing 92", created: "2016-05-20T01:44:56.113", status: "Live"},
{type: "Listener", component: "22064", created: "2016-05-20T01:44:56.113", status: "Live"},
{type: "Dispacther", component: "Dispacther1", created: "2016-05-21T00:48:50.433", status: "Warning"}
];
私の試み: すべてがngif
ディレクティブ
マイアレイ以外の作品
<tr ng-repeat="component in components">
<td >{{component.type}}</td>
<td>{{component.component}}</td>
<td>{{component.created}}</td>
<td ng-if="component.status == Live" class="alert-success">{{component.status}}</td>
<td ng-if="component.status == Warning" class="alert-warning">{{component.status}}</td>
<td ng-if="component.status == Down" class="alert-danger">{{component.status}}</td>
</tr>
ここhttps://docs.angularjs.org/api/ngドキュメントをチェックNGクラスのディレクティブを使用しない理由/ directive/ngClass – Ayoub
私が正しく覚えていれば、スコープ変数でない限り、 'Live'などを一重引用符で囲みたいとします。 –
@SterlingArcherこれは完璧に機能しました。どうもありがとうございました。 –