In the following Angular2 program where I want the system to randomly choose four choices from either 0 or 1. I'm getting the desired output and the console doesn't report any error. However, my IDE displays the following error:
I tried changing Number
to number
but it yields another error:
Component Code
import {Component} from 'angular2/core';
import {OnInit} from 'angular2/core';
@Component(
{
selector: 'puzzle',
template: `
<section class="bination">
I: {{ switch1Number }}<br>
II: {{ switch2Number }}<br>
III: {{ switch3Number }}<br>
IV: {{ switch4Number }}
</section>
`
})
export class PuzzleComponent implements OnInit {
switch1Number = Number;
switch2Number = Number;
switch3Number = Number;
switch4Number = Number;
ngOnInit() {
// Math.randon gives a random decimal value between 0 & 1.
// Math..round rounds it to 0 or 1
this.switch1Number = Math.round(Math.random());
this.switch2Number = Math.round(Math.random());
this.switch3Number = Math.round(Math.random());
this.switch4Number = Math.round(Math.random());
console.log(this.switch1Number, this.switch2Number, this.switch3Number, this.switch4Number);
}
}
In the following Angular2 program where I want the system to randomly choose four choices from either 0 or 1. I'm getting the desired output and the console doesn't report any error. However, my IDE displays the following error:
I tried changing Number
to number
but it yields another error:
Component Code
import {Component} from 'angular2/core';
import {OnInit} from 'angular2/core';
@Component(
{
selector: 'puzzle',
template: `
<section class="bination">
I: {{ switch1Number }}<br>
II: {{ switch2Number }}<br>
III: {{ switch3Number }}<br>
IV: {{ switch4Number }}
</section>
`
})
export class PuzzleComponent implements OnInit {
switch1Number = Number;
switch2Number = Number;
switch3Number = Number;
switch4Number = Number;
ngOnInit() {
// Math.randon gives a random decimal value between 0 & 1.
// Math..round rounds it to 0 or 1
this.switch1Number = Math.round(Math.random());
this.switch2Number = Math.round(Math.random());
this.switch3Number = Math.round(Math.random());
this.switch4Number = Math.round(Math.random());
console.log(this.switch1Number, this.switch2Number, this.switch3Number, this.switch4Number);
}
}
Share
Improve this question
edited Dec 3, 2016 at 4:22
anonym
asked Dec 3, 2016 at 4:12
anonymanonym
4,85012 gold badges51 silver badges76 bronze badges
1 Answer
Reset to default 3Replace Number
with number
in
switch1Number = Number
it should be
switch1Number: number;
Number
is not a type of variable, it's a number constructor
just likeString
is a string
type constructor
.