Gaurav Aggarwal Gaurav Aggarwal - 8 months ago 29
AngularJS Question

Why ng-class-even required extra quotes

I am working on angularJS where my codes are fine but i am stuck at one place where i cant find why extra quotes are required in


In this line
<tr ng-repeat="x in records" ng-class-even='"striped"'>
why striped is written like this
instead of this

.striped {

<body ng-app="myApp">
<script src=""></script>

<table ng-controller="myCtrl">
<tr ng-repeat="x in records" ng-class-even="'striped'">

var app = angular.module("myApp", []);
app.controller("myCtrl", function($scope) {
$scope.records = [
"Name" : "Alfreds Futterkiste",
"Country" : "Germany"
"Name" : "Berglunds snabbköp",
"Country" : "Sweden"
"Name" : "Centro comercial Moctezuma",
"Country" : "Mexico"
"Name" : "Ernst Handel",
"Country" : "Austria"



This is because ng-class-even allows to give a expression. In your question you says:

n this line why striped is written like this "'striped'" instead of this "striped"

if you will try be do this, Angular thinks that striped is a variable attached in the $scope. So using 'striped' tells to angular that the expression that you passed to the directive is a string value