简体   繁体   English

Angular / Ionic NG-Class没有做任何事情

[英]Angular/Ionic NG-Class isnt doing anything

i have a problem: 我有个问题:
im new to ionic/angular and im not able to make ng-class work 我很新的离子/角度,我不能做ng级工作

 <ion-content padding> <ion-grid> <ion-row> <ion-col> <ion-row> <ion-col *ngFor="let field1 of gs.fields; let x = index; trackBy: trackByFn"> <!-- new row if x % 3 == 0 --> <ion-col *ngFor="let field2 of field1; let y = index; trackBy: trackByFn"> <ion-row> <ion-col class="ctr fc tile" *ngFor="let tile of field2; let z = index; trackBy: trackByFn" (click)="playerClick(x,y,z)"> <span class="ctr" ng-class="{'player1': tile==1, 'player2' : tile==2}">{{(tile==0)? ' ': ((tile==1)? 'x' : 'o')}}</span> </ion-col> </ion-row> </ion-col> </ion-col> </ion-row> </ion-col> </ion-row> </ion-grid> </ion-content> 

(click)="playerClick(x,y,z)"

Is getting Called in my Service, so i shouldnt be mission any ng-model right? 在我的服务中被调用,所以我不应该成为任何ng模型的任务吗?
I mean {{(tile==0)? ' ': ((tile==1)? 'x' : 'o')}} 我的意思是{{(tile==0)? ' ': ((tile==1)? 'x' : 'o')}} {{(tile==0)? ' ': ((tile==1)? 'x' : 'o')}} is working, so Angular should have every variable im using right? {{(tile==0)? ' ': ((tile==1)? 'x' : 'o')}}正在工作,所以Angular应该让每个变量使用正确吗?

How its shown in the Browser: 如何在浏览器中显示:

<ion-col class="ctr fc tile col">
<span class="ctr" ng-class="{'player1': tile==1, 'player2' : tile==2}">x</span>
</ion-col>


I also tried to call a Function inside my Service from ng-style and console log inside the function to test if its called but it wasnt. 我还尝试在函数内部调用ng-style和console log中的函数来测试它是否被调用但是它不是。
Example: <span class="ctr" ng-style="{'color':getTileColor(tile)}">{{(tile==0)? ' ': ((tile==1)? 'x' : 'o')}}</span> 示例: <span class="ctr" ng-style="{'color':getTileColor(tile)}">{{(tile==0)? ' ': ((tile==1)? 'x' : 'o')}}</span> <span class="ctr" ng-style="{'color':getTileColor(tile)}">{{(tile==0)? ' ': ((tile==1)? 'x' : 'o')}}</span>


Furthermore i would like to force a new row if x%3 == 0 Im thinking of something like (but it isnt working): 此外,我想强制一个新的行,如果x%3 == 0我想的东西(但它不工作):

 <ion-content padding> <ion-grid> <ion-row> <ion-col> <ion-col *ngFor="let field1 of gs.fields; let x = index; trackBy: trackByFn"> <ion-row ng-if "x % 3 == 0"> <!-- new row if --> <ion-col *ngFor="let field2 of field1; let y = index; trackBy: trackByFn"> <ion-row> <ion-col class="ctr fc tile" *ngFor="let tile of field2; let z = index; trackBy: trackByFn" (click)="playerClick(x,y,z)"> <span class="ctr" ng-class="{'player1': tile==1, 'player2' : tile==2}">{{(tile==0)? ' ': ((tile==1)? 'x' : 'o')}}</span> </ion-col> </ion-row> </ion-col> </ion-row ng-if "x % 3 == 0"> </ion-col> </ion-col> </ion-row> </ion-grid> </ion-content> 

^ I put ion-row inside the first nGFor there 我把离子排放在第一个nGFor里面

<ion-row ng-if "x % 3 == 0">

ROWS how it is ROWS怎么样
ROWS how it should be ROWS它应该如何

i think you're confusing angular 1 with angular 2. 我认为你将角度1与角度2混淆。

ng-style and ng-class are angular 1 syntax ng-styleng-class是angular 1语法

in angular 2 and above the correct way to invoke these directives is: 在角度2及以上,调用这些指令的正确方法是:

[ngClass]="{'player1': tile==1, 'player2' : tile==2}"
[ngStyle]="{'font-size': fontSize+'px'}"

link to docs 链接到docs

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM