-
Notifications
You must be signed in to change notification settings - Fork 25.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Why can it work without specifying an operator (@) in services? #21382
Comments
This happens because Injectable()
export class AuthService { ... }
// same as
console.log('this does nothing')
export class AuthService { ... } If you add Note that the Alternatively, you can omit the export class AuthService { ... }
@Component({ ... })
export class AppComponent {
constructor(@Inject(AuthService) private auth: AuthService) {}
} In any case, I would classify this as working as intended and not a bug or shortcoming of Angular. I'm pretty sure that the requirement of using the |
But, unfortunately, this increases the learning curve... if taken for granted |
It seems that compiler check for Also, see #18604:
It just doubles confusion about future and current state of |
Even if I connect the wrong service, it will not work until I add the correct @ operator, which means that there is no special check |
It's frustrating... |
My bad it's not for checking misused decorator factory function.
|
Why would he do this? (Because, we are used to the old Injector) |
Sorry this works as intended, even if it is confusing per explanation above. |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Adequate behavior
If I write this code, the compiler will swear
Inadequate behavior
But if I write this code, the compiler will not swear
app.component.ts
app.module.ts
That is, I am purely allowed from the beginning to write Injectable without an operator (@). So, it can lead me here:
Uncertain behavior
app.component.ts
app.module.ts
But I would expect from the very beginning
The worst after
The worst thing is that if I add an immediately missed statement (@), it means that ng serve does not work properly after that.
Environment
Angular version: 5.1.3
Browser: Chrome 63
Node version: 8.7.0
Windows 10
The text was updated successfully, but these errors were encountered: