admin管理员组文章数量:1356413
I need to add both my service as well as an authentication service to my appponent.ts, but I can't seem to add both in my constructor parameters. How can I do that and still have both available to the whole application? Here's what I have:
constructor(private _dataService: DataService, authToken: Angular2TokenService) {
this.authToken.init(environment.token_auth_config)
}
The error is: Property 'authToken' does not exist on type 'AppComponent'.
All necessary items have already been imported.
How can I write both in? Most answers I'm finding are for older versions of Angular. Thanks.
I need to add both my service as well as an authentication service to my app.ponent.ts, but I can't seem to add both in my constructor parameters. How can I do that and still have both available to the whole application? Here's what I have:
constructor(private _dataService: DataService, authToken: Angular2TokenService) {
this.authToken.init(environment.token_auth_config)
}
The error is: Property 'authToken' does not exist on type 'AppComponent'.
All necessary items have already been imported.
How can I write both in? Most answers I'm finding are for older versions of Angular. Thanks.
Share Improve this question asked Aug 22, 2018 at 15:31 Devstar34Devstar34 1,0972 gold badges27 silver badges57 bronze badges2 Answers
Reset to default 7Add private
before authToken
. Adding private
makes it a property of the Component class. Then you can refer to the authToken
with the this
keyword.
constructor(private _dataService: DataService, private authToken: Angular2TokenService) {
this.authToken.init(environment.token_auth_config)
}
You have used this
with authToken
- this means that your authToken
is declared as property of your ponent but currently it is not like that so why you get the error.
You need to add private
or another access modifier before the authToken
. This tells that the parameter in the constructor is declared as a property of the ponent like _dataService
constructor(private _dataService: DataService, private authToken: Angular2TokenService) {
this.authToken.init(environment.token_auth_config)
}
本文标签: javascriptAngular 5 How to add multiple parameters to constructorStack Overflow
版权声明:本文标题:javascript - Angular 5- How to add multiple parameters to constructor? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744057900a2583588.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论