動作しています。私のプランカーを参照してください: https://plnkr.co/edit/ZIjepnYZ5IS8FfktU0C1?p=preview
images[i]
毎回割り当てるのではなく、それらを配列にプッシュする必要があります。
import {Component, NgModule, Input} from '@angular/core'
import {BrowserModule} from '@angular/platform-browser'
@Component({
selector: 'my-cmp',
template: `my-cmp!`,
})
export class MyCmp {
private _images: any[];
private _threeImages: any[];
@Input() set images(images: any[]) {
this._images = images;
this._threeImages = []; // CLEAR IT !
for(let i=0; i < 3; i++) {
this._threeImages.push(images[i]);
}
console.log(this._images);
console.log(this._threeImages);
}
}
@Component({
selector: 'my-app',
template: `
<div>
<h2>Hello {{name}}</h2>
</div>
<my-cmp [images]="myImages"></my-cmp>
`,
})
export class App {
private myImages: any[] = [
{},
{},
{},
{},
{}
];
constructor() {
this.name = 'Angular2'
}
}
@NgModule({
imports: [ BrowserModule ],
declarations: [ App, MyCmp ],
bootstrap: [ App ]
})
export class AppModule {}