Domanda

Sono nuovo a Angularjs.

Voglio aggiungere una classe alla seconda colonna in base al suo valore. Esempio: voglio aggiungere la classe 'positivo' se il valore è> 0 e classe 'negativo' quando è <0.

Cosa sto usando attualmente:

<td data-ng-class="{positive: $index==1 && {{values}} > 0 , negative:{{values}} < 0 && $index==1 }" ng-repeat="values in portfolio" >{{values}}</td>
.

Ora, sembra funzionare (vedi immagine):

Inserire l'immagine Descrizione qui

Ma, sto ottenendo il seguente nella mia console:

Errore: [$ Parse: Sintassi] http://errors.angularjs.org/1.2. 7 / $ Parse / Sintassi? P0=% 26 & p1= è% 20UNExpected% 2C% 20Especting% 20% 5b% 7D% 5D & P2= 26 & P3=% 7Bpositive% 3A% 20% 24Index% 3D% 3D1% 20% 26 % 26% 20s% 26p500% 20% 3e% 200% 20% 2C% 20negativo% 3S% 26p500% 20% 3C% 200% 20% 26% 26% 20% 24Index% 3D% 3D1% 20% 7D & P4=% 26p500% 20% 3e% 200% 20% 2C% 20negativo% 3S% 26p500% 20% 3C% 200% 20% 26% 26% 20% 24Index% 3D% 3D1% 20% 7D All'errore () A https://ajax.googleapis .com / ajax / libs / angularjs / 1.2.7 / angolar.min.js: 6: 449 a xa.throwerror ( https: / /ax.googleapis.com/ajax/libs/angularjs/1.2.7/angular.min.js:155:346 ) a xa.consume ( https: / /ax.googleapis.com/ajax/libs/angularjs/1.2.7/angular.min.js:156:325 ) a xa.object ( https: / /ax.googleapis.com/ajax/libs/angularjs/1.2.7/angolare.min.js:164:115 ) a xa.primary ( https: / /ax.googleapis.com/ajax/libs/angularjs/1.2.7/angular.min.js:154:482 ) a xa.unary ( https: / /ax.googleapis.com/ajax/libs/angularjs/1.2.7/angolare.min.js:161:240 ) a xa.multiplicative ( https: / /ax.googleapis.com/ajax/libs/angularjs/1.2.7/angolare.min.js:160:480 ) a xa.Additive ( https: / /ax.googleapis.com/ajax/libs/angularjs/1.2.7/angolare.min.js:160:325 ) a xa.relational ( https: / /ax.googleappis.com/ajax/libs/angularjs/1.2.7/angular.min.js:160:204 )

È stato utile?

Soluzione

Prova:

<td data-ng-class="{positive: $index==1 && values > 0, negative:values < 0 && $index==1 }" ng-repeat="values in portfolio" >{{values}}</td>
.

Altri suggerimenti

È necessario modificare {{values}} in values

<td data-ng-class="{positive: $index==1 && values > 0 , negative:values < 0 && $index==1 }" ng-repeat="values in portfolio" >{{values}}</td>
.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top