私はAngular 2 betaとTypescript("gulp-typescript": "~2.12.1",
)を使用しています。typescript長さが新しい配列
私は<div qz-badge num-stars="3" class="qz-badge"></div>
import {Component, Input, ElementRef} from 'angular2/core';
import {CORE_DIRECTIVES} from 'angular2/common';
@Component({
selector: '[qz-badge]',
directives: [CORE_DIRECTIVES],
template: `
<div class="stars">
</div>
`
})
export class Badge {
@Input('num-stars') numStars: number;
constructor() {
console.log(new Array(3));
}
ngOnInit() {
let num = this.numStars;
console.log(num);
console.log('--------');
this.stars = new Array(num);
console.log(this.stars);
console.log(this.stars.length);
num = 3;
console.log('--------');
this.stars = new Array(num);
console.log(this.stars);
console.log(this.stars.length);
}
}
のためのコンポーネントを書いていますこれは仕様で..
3 -------- ["3"] 1 -------- [] 3
をリードし、
構文
[element0, element1, ..., elementN]
new Array(element0, element1[, ...[, elementN]])
new Array(arrayLength)
(https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)
長さは3であるべきだと思います。 これはバグですか、いくつかの正しい理由がありますか?
'numStars'は数字として定義されていますが、' console.log(this.numStars + 1) 'は31で、4ではなく' ParseInt'できませんでした。 'let num = + this.numStars;'は最終的に3行の配列を導いた。それは奇妙だ。 – Kennyhyun