A
A
Arthur Gurinovich2014-11-28 11:51:01
Angular
Arthur Gurinovich, 2014-11-28 11:51:01

How to load css class using Angular?

Good afternoon,
There was a small question:
The site has a slider into which data is loaded from a JSON file.
For each individual slide, I wanted to load different styles.

<section class="intro" id="intro" id="ng-app" ng-app ng-controller="PostsCtrlAjax">
  <div class="intro-slider" ng-repeat="post in posts">
    <div class="item one" > <!-- Вот здесь нужно подгружать class для конкретного слайда-->
      <div class="container" >
        <div class="row">
          <div class="col-md-6 col-sm-6 paddingtop">
            <img ng-src="{{post.logo}}" class="logo" alt="logo">
            <h1>{{post.title}}</h1>
          </div>
        </div>
      </div>
    </div>
  </div>
</section>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mikhail Osher, 2014-11-28
@ArthurGurinovich

1) create an object with styles like:

// Где-то в контроллере
$scope.styles = {type1: 'class1 classX', type2: 'class2 classY'};

2) add ngClass directive
<!-- скажем, у поста есть некий идентификатор - type -->
<div class="item one" ng-class="styles[post.type]">

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question