2014-07-15 2 views
0

나는 각도가 완전히 새롭습니다. 그리고이 일로 인해 어려움을 겪고있는 것이 하루 종일입니다. 내가 필요로하는 것은 간단하다Angularjs 라디오 버튼에서 래퍼의 색상을 변경했습니다.

<div class="row lines" ng-class="class" ng-model="hotel"> 
     <div class="col-xs-6"> 
      <label class="control radio"> 
       <input type="radio" id="hotel3" name="hotel" value="LeonardodaVinci" ng-model="hotel"> 
       <span class="control-indicator"></span> 
       NH Leonardo da Vinci 
      </label> 
     </div> 
     <div class="col-xs-3 text-center"> 
      € 280.00 

     </div> 
     <div class="col-xs-3 text-center"> 
      € 320.00 
     </div> 

    </div> 

    <div class="row lines" ng-class="class" ng-model="hotel"> 
     <div class="col-xs-6"> 
      <label class="control radio"> 
       <input type="radio" id="hotel4" name="hotel" value="Giustiniano" ng-model="hotel"> 
       <span class="control-indicator"></span> 
       Nh Giustiniano 
      </label> 
     </div> 
     <div class="col-xs-3 text-center"> 
      € 280.00 
     </div> 
     <div class="col-xs-3 text-center"> 
      € 320.00 
     </div> 
    </div> 
    <div class="row lines" ng-class="class"> 
     <div class="col-xs-6"> 
      <label class="control radio"> 
       <input type="radio" id="hotel4" name="hotel" value="GrandHotelTiberio" ng-model="hotel"> 
       <span class="control-indicator"></span> 
       Grand Hotel Tiberio 
      </label> 
     </div> 
     <div class="col-xs-3 text-center"> 
      € 280.00 
     </div> 
     <div class="col-xs-3 text-center"> 
      € 320.00 
     </div> 
    </div> 

: :이 경우 내 래퍼 사업부의 .lines에 클래스를 추가 할 필요가

내 코드입니다.

<div class="row lines" ng-class="('{{hotel}}' === 'LeonardodaVinci') ? 'selected' : ''"> 

이 : 그들 중 누구도 작동하지 보인다

<div class="row lines" ng-class="{ 'selected' : '{{hotel}}' === 'LeonardodaVinci' }"> 

하지만 그물에 많은 예제를 읽은 후 나는이 tryed했습니다. 내 감찰관에서는 위의 두 예제 모두에서 {{hotel}}이 올바른 값을 얻지 만 어떤 것도 내 래퍼에 클래스를 추가하지 않음을 알 수 있습니다.

이 답변은 기본적으로 광산과 동일합니다. Angularjs - How to change background color using radio button 하지만 작동하지 않는 것처럼 보이고 중계기를 아직 만들지 못했습니다.

감사

답변

0

이 지침은 식을 평가하는 세 가지 유형의에 따라, 세 가지 방법으로 운영에 :

1.If the expression evaluates to a string, the string should be one or more space-delimited class names. 

2.If the expression evaluates to an array, each element of the array should be a string that is one or more space-delimited class names. 

3.If the expression evaluates to an object, then for each key-value pair of the object with a truthy value the corresponding key is used as a class name. 

양식 3을 사용할 수 있습니다.

ng-class = "{selected : hotel === 'LeonardodaVinci'}"

+0

고마워, 내가 그 모든 가능성을 시도했지만 어쩌면 내가 이것을 놓쳤다. 어쩌면 처음에 나는 3 개의 동등 물을 사용하지 않았기 때문에, 단지 2 개, 또는 어쩌면 내가 그 꼭두각시를 놓 쳤기 때문에. 어쨌든 당신을 대단히 감사합니다! – danieleb

0

닫기, 도랑 {{}} 각도 지침 이내에 서면으로 할 때 :

ng-class="{ 'selected' : hotel === 'LeonardodaVinci' }"> 
+0

고마워, 나는이 문법을 시도했지만 뭔가를 놓친 것 같아서 효과가 있었다. – danieleb