Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/29.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ionic-framework/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 具有ngFor属性的元素上的变量的附加类_Angular_Ionic Framework_Ionic2 - Fatal编程技术网

Angular 具有ngFor属性的元素上的变量的附加类

Angular 具有ngFor属性的元素上的变量的附加类,angular,ionic-framework,ionic2,Angular,Ionic Framework,Ionic2,这是显示列表的“我的离子”按钮: <button ion-item text-wrap *ngFor="let task of tasks" (click)="gotoTask(task)"> 它产生: <button class="item-block item item-ios" ion-item="" text-wrap=""> 当我尝试以这种方式添加类时 <button ion-item text-wrap *ngFor="let task of

这是显示列表的“我的离子”按钮:

<button ion-item text-wrap *ngFor="let task of tasks" (click)="gotoTask(task)">

它产生:

<button class="item-block item item-ios" ion-item="" text-wrap="">

当我尝试以这种方式添加类时

<button ion-item text-wrap *ngFor="let task of tasks" (click)="gotoTask(task)" class="{{task.status}}">

它会中断并最终成为:

<button class="completed" ion-item="" text-wrap="" ng-reflect-class-name="completed">

这看起来显然不对


向按钮添加类的正确方法是什么?

更好的方法是使用
ngClass
指令

<button ion-item text-wrap *ngFor="let task of tasks" 
    (click)="gotoTask(task)" 
    [ngClass]="task.status">

ng reflect class name=“completed”
是Angular2为内部处理添加的信息。

您觉得什么不合适?I
class=“completed”
不是你想要的?哈,你得到了。谢谢你的回答。
[class.someStaticClass]="booleanExpression"