पर आधारित वर्ग जोड़ें बस कुछ सही होने पर कक्षा को लागू करने का प्रयास कर रहा है। प्रलेखन यहाँ मेरी नकली वस्तुएंगुलरजेएस: मॉडल
$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
}}
];
है और यहाँ मेरी मार्कअप है http://docs.angularjs.org/api/ng.directive:ngClass
li
1 === true
अगर
पर favorite
के एक वर्ग को जोड़ने के लिए कोशिश कर रहा है पर बहुत संक्षिप्त है।
<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, आदि)
किसी को भी मुझे सही दिशा में बात कर सकते हैं करने के लिए काम नहीं करता है? :}
भय, मैं बहुत करीब था! यह पूरी तरह से काम करता है। आपका बहुत बहुत धन्यवाद! –
"-" से अलग वर्गों के लिए, वर्ग नामों को 'वर्गनाम' जैसे उद्धरणों में सिंटैक्स त्रुटियों से बचने के लिए रखें – imsheth