in plnkr我重现了一个奇怪的边缘情况。它可能取决于 pixjs 或 webgl,因为它在使用 pixjs 时发生。
请注意如何单击列表中的所有元素,但是一旦开始使用 pixij(只需单击按钮),单击就会停止对数组类型的元素起作用。这odd问题是它仍然适用于所有其他元素。这是偶数如果不使用函数返回数组,而是使用内联数组,那么一切都会按预期工作......
有任何想法吗 ?
应用程序组件.ts
<button *ngIf="!renderer" (click)="breakIt()">break me</button>
<span *ngIf="renderer">BROKEN</span>
Clicked: {{clicked | json}}
<h2>It breaks</h2>
<h3 *ngFor="#n of ns()" (click)="click(n)">{{n | json}}</h3>
<h2>It works</h2>
<h3 *ngFor="#n of [[2,4],'ciao',4,true]" (click)="click(n)">{{n | json}}</h3>
应用程序组件.html
import {Component} from 'angular2/core';
@Component({
selector: 'my-app',
templateUrl: './app/app.component.html'
})
export class AppComponent {
clicked = "";
renderer;
breakIt() {
this.renderer = PIXI.autoDetectRenderer(200, 200,{backgroundColor : 0x1099bb});
}
ns() {
return [[2,4],'ciao',4,true];
}
click(n) {
this.clicked=n;
}
}
问题是由
ns() {
return [[2,4],'ciao',4,true];
}
and
<h3 *ngFor="#n of ns()"
对于每个事件,Angular 都会调用更改检测,并且每次都会检查之前返回的值是否来自ns()
与当前的相同,结果每次都不同,因为每次调用ns()
返回一个新数组。 Angular 预计模型会稳定下来。
Angular 不会比较对象和数组的属性或内容,它只进行身份检查和ns()
每次调用都会返回一个新的、不同的数组实例。
相反,它应该是
var arr = [[2,4],'ciao',4,true];
ns() {
return this.arr;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)