2017-04-04 1 views
1

私は配列またはcolors = ['Red'、 'White'、 'Gold'、 'Black']を持っています。 は私がアレイのng-repeatの内部でng-ifを使用するにはどうすればよいですか?

<span ng-repeat="color in item.colorOptions" ng-init="color"> 
    <lable ng-if="'Red' == {{color}}"> This is Red..</lable> 
    <lable ng-if="'Black' == {{color}}"> This is Black..</lable> 
</span> 

なぜNG-場合は、上記のコードのように使用することはできません。..コードの下のような何かをしようとしていましたか?理由とは何ですか?ここでng-ifまたはng-show/hideを使用する代替方法は何ですか?

+0

ここで想定item.colorOptions = [ 'レッド'、 'ホワイト'、 'ゴールド'、 'ブラック']; – Laxmikant

答えて

1

それがあるべき、

<span ng-repeat="color in item.colorOptions" ng-init="color"> 
    <lable ng-if="color === 'Red'"> This is Red..</lable> 
    <lable ng-if="color === 'Black'"> This is Black..</lable> 
</span> 

DEMO

var myApp=angular.module('myApp',[]) 
 
myApp.controller('myController',function($scope){ 
 
    $scope.item = {}; 
 
    $scope.item.colorOptions = ['Red', 'White', 'Gold', 'Black']; 
 
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script> 
 
<div ng-app='myApp' ng-controller='myController'> 
 
    <span ng-repeat="color in item.colorOptions" ng-init="color"> 
 
    <lable ng-if="color === 'Red'"> This is Red..</lable> 
 
    <lable ng-if="color === 'Black'"> This is Black..</lable> 
 
</span> 
 
</div>

関連する問題