무언가 사실이라면 클래스를 적용하려고합니다. 문서는 여기 내 모의 객체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