0
ここに状況があります。角度2配列は "undefined"となります
私は自分のデータベースから数値を取得しようとしていますが、Array()に数値を入れるたびに、定義されていません。
私はHTMLで表示することができますが、配列の中で数字を取得することはできません。
これはなぜ起こっているのでしょうか?
import { Component, OnInit } from '@angular/core';
import { DomSanitizer, SafeResourceUrl, SafeUrl, SafeHtml } from '@angular/platform-browser';
import { ActivatedRoute } from '@angular/router';
import { RealEstatePhotography } from '../real-estate-photography';
import { RealEstatePhotographyService } from '../real-estate-photography.service';
@Component({
selector: 'app-real-estate-photography-detail',
templateUrl: './real-estate-photography-detail.component.html',
styleUrls: ['./real-estate-photography-detail.component.css'],
providers: [RealEstatePhotographyService],
})
export class RealEstatePhotographyDetailComponent implements OnInit {
realEstate;
amount
photos = Array(this.amount)
constructor(private route: ActivatedRoute, private _realEstatePhotographyService: RealEstatePhotographyService, private sanitizer: DomSanitizer) {}
ngOnInit(){
this.route.params.subscribe(params => {
let title = params['title'];
let realEstate = this._realEstatePhotographyService.getItem(title).subscribe(realEstate => {
this.realEstate = realEstate;
this.amount = this.realEstate.amount
});
});
}
}
親愛なるChrispy、 ありがとうございます。それはそのようには動作しませんでしたが、私にそれを行う方法のアイデアを与えました。 私はそれを最終的に解決することができました。私はちょうど 写真=アレイ(this.realEstate.amount) をngOnInit()メソッドの中に入れました。 もう一度、ありがとうございます –
問題ありません!その時点であなたの例では "this.realEstate.amount"は常に未定義です... – chrispy