何かが真であればクラスを適用しようとしています。ドキュメントはここに私のモックオブジェクトAngularJs:モデルに基づいてクラスを追加する
$scope.restaurantListFromSearch = [
{restaurantName: "Zocala",
details: {
image: "http://placehold.it/124x78",
url: "#",
cuisineType: ["Sandwiches", "American", "BBQ"],
description: "Modern, healthy, awesome BBW",
priceRange: "$",
userFavorite: 0
}},
{restaurantName: "Subway",
details: {
image: "http://placehold.it/124x78",
url: "#",
cuisineType: ["Sandwiches", "American", "BBQ"],
description: "Modern, healthy, awesome BBW",
priceRange: "$",
userFavorite: 1
}},
{restaurantName: "Hungry Howies",
details: {
image: "http://placehold.it/124x78",
url: "#",
cuisineType: ["Sandwiches", "American", "BBQ"],
description: "Modern, healthy, awesome BBW",
priceRange: "$",
userFavorite: 0
}}
];
だとここで私のマークアップですli
1 === true
場合
にfavorite
のクラスを追加しようとしhttp://docs.angularjs.org/api/ng.directive:ngClass
に非常に簡単です。
<ul>
<li ng-repeat="restaurant in restaurantListFromSearch" ng-class="{restaurant.details.userFavorite === 1: favorite}">
<img src="{{restaurant.details.image}}" alt="{{restaurant.restaurantName}}">
<div class="details">
<a href="{{restaurant.details.url}}">{{restaurant.restaurantName}}</a>
<span class="cuisine-type">{{restaurant.details.cuisineType}}</span>
<p>{{restaurant.details.description}}</p>
<span class="price-rating">{{restaurant.details.priceRange}}</span>
</div>
<div class="clear"></div>
</li><!-- end restaurant result -->
</ul>
読みやすくするために
追加jsFiddle、実際に(requireJs、など)
は誰が正しい方向に私を指すため、行方不明の依存関係には動作しませんか? :}
私はとても近かった!これは完全に機能します。どうもありがとうございました! –
" - "で区切られたクラスの場合は、クラス名を 'classname'のような引用符で囲んで構文エラーを避けます – imsheth