athi athi -5 years ago 165
HTML Question

ng-if condition always fails

I'm using AngularJS

<div ng-repeat="l in kites">
<a ng-click="findit(">color</a>
<span ng-if="c_{{}} == 'y'>kites is </span>

In my controller I have

$scope.findit = function(c){
angular.forEach($scope.cnt, function(value, key){
$scope['c_'+value] = 'y' ;


My problem is, I'm not getting the span value even the conditions falls true..
means while
is 5 ,
c_5 ='y'
. But it is not accepted in the if condition. Please help me.

Answer Source

Below is your solution:

var $scope;
var app = angular.module('miniapp', []);

function Ctrl($scope) {
	$scope.kites = [{
  $scope.cnt = [];
  $scope.findit = function(c) {
    angular.forEach($scope.cnt, function(value, key) {
      $scope['c_' + value] = 'y';


<script src=""></script>
<div ng-app="miniapp" ng-controller="Ctrl">
  <div ng-repeat="l in kites">
    <a ng-click="findit(">color</a>
    <span ng-show="{{'c_'}} == 'y'">kites is </span>

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download