• Register
0 votes
4.4k views

Problem:

I am currently wondering why I am getting below compile error if I just declare variable with var or let keywords? I want to say, below code goes well:

export class MyAppComponent {
myRefreshClickStream$: any;
constructor(){
}
}

While this brings the error:

export class MyAppComponent {
var myRefreshClickStream$: any;
constructor(){
}
}

 

7 5 2
3,870 points

Please log in or register to answer this question.

1 Answer

0 votes

Solution :

If you look inside your class carefully, then you will realize that TypeScript will not permit a declaration of class members by

· Using var keyword

· Using let keyword

· Using const (you can use readonly on the property)

Also, if you look inside of a class then you will realize that you will be prohibited from declaring the functions by

· Using function keyword

So the correct way to write the code which you were looking for is as below :

export class MyAppComponent {
  x: string = "fooo";

  y: string = "barr";

 fooo(): void { }

constructor(){

  }

}

And clearly not the way as shown below,

export class MyAppComponent {

var x: string = "fooo";

let y: string = "barr";

function fooo(): void { }

constructor(){

  }

}

Hope the above mentioned code and explanation will surely help you in clearing your doubts related to coding.

9 7 4
38,600 points

Related questions

0 votes
1 answer 26 views
26 views
Problem: I am currently wondering why I am getting below compile error:Unexpected token. a constructor, method, accessor, or property was expected..
asked Mar 6 Wafa Abu Yousef 6.1k points
0 votes
1 answer 17 views
17 views
Problem: How can I fix this : Can't bind to 'formcontrol' since it isn't a known property of 'input'
asked Mar 14 Wafa Abu Yousef 6.1k points
1 vote
2 answers 188 views
188 views
Problem : I am beginner to Angular2. Currently I am trying to create a simple form in the Angular2 app but it is not working for me. I am facing below error. “Can't bind to 'formGroup' since it isn't a known property of 'form'.” I am struggling on this error from couple of days. Still I don’t know how to fix above error. Is it possible for somebody to fix it for me?
asked Mar 27, 2020 morrisBson 3.2k points
0 votes
1 answer 2.2K views
2.2K views
Problem : I am beginner in using Angular material. I am trying to use autocomplete component in the Angular2 project. Please find below the code written for my component. import {Component, OnInit} from "@angular/core"; import {ActivatedRoute, Router} from "@angular/router"; ... ; I am struggling with this issue from past 2 days but unable to resolve it. Can somebody help me in fixing this issue?
asked Feb 27, 2020 mphil 2.3k points
0 votes
1 answer 95 views
95 views
Problem : I am facing below error when trying to launch my Angular app, even if my component is not displayed at all. “Can't bind to 'ngmodel' since it isn't a known property of 'input'. ("” How can I fix this issue?
asked Feb 19, 2020 mphil 2.3k points
0 votes
1 answer 896 views
896 views
Problem : I am facing below error as : node_modules/rxjs/internal/types.d.ts(81,44): error TS1005: ';' expected. After I tried to do the installation of Angular 6. Check the detailed error as below : ERROR in node_modules/rxjs/internal/types.d.ts(81,44): ... internal/types.d.ts(81,76): error TS1005: ';' expected. node_modules/rxjs/internal/types.d.ts(81,78): error TS1109: Expression expected.
asked Dec 18, 2019 alecxe 7.5k points
0 votes
1 answer 204 views
204 views
Problem: I am naive to Angular, Webpack, Bootstrap and typescript. I have tried to write a service but it is throwing the below error while my app is bootstrapping. I am currently using ng2 2.4.2 and the angular-cli 1.0.0-beta.24. My TypeError as below: “Uncaught typeerror: ... .navigate(['/project', query]); } public extractData(res: Response) { let body = res.json(); return body || {}; } }
asked Sep 3, 2020 Raphael Pacheco 4.9k points
0 votes
1 answer 249 views
249 views
Problem : I have upgraded my Angular 4 project using angular-seed but now facing following error please include either "browseranimationsmodule" or "noopanimationsmodule" in your application.
asked Nov 14, 2019 peterlaw 6.9k points
0 votes
1 answer 3 views
3 views
Problem: created my routing in my app. module. But when I run this I get the following error: Router-outlet' is not a known element: It gives an error telling me that Visual Studio cannot resolve the tag 'router outlet. Any suggestions on how I can fix this error?
asked Mar 27 ummesalma 25.2k points
0 votes
1 answer 1 view
1 view
Question: I'm developing with Ionic 2 and am having a problem with Typescript component templates. From a page, DataPage in the code below, I need to generate and present a modal view when a button is clicked. When I use templateUrl in the modal component, I am presented with an ... this? I don't mind working with template in the short term, but that isn't going to fly when I'm ready to release.
asked 3 days ago Atik03 10.1k points