Title: Why can it work without specifying an operator (@) in services? · Issue #21382 · angular/angular · GitHub
Open Graph Title: Why can it work without specifying an operator (@) in services? · Issue #21382 · angular/angular
X Title: Why can it work without specifying an operator (@) in services? · Issue #21382 · angular/angular
Description: Adequate behavior If I write this code, the compiler will swear Component({ selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.css'] }) Unexpected value 'AppComponent' declared by the module 'AppModul...
Open Graph Description: Adequate behavior If I write this code, the compiler will swear Component({ selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.css'] }) Unexpected value 'AppCom...
X Description: Adequate behavior If I write this code, the compiler will swear Component({ selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.css'] }) ...
Opengraph URL: https://github.com/angular/angular/issues/21382
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Why can it work without specifying an operator (@) in services?","articleBody":"## Adequate behavior\r\n\r\nIf I write this code, the compiler will swear\r\n\r\n```typescript\r\nComponent({\r\n selector: 'app-root',\r\n templateUrl: './app.component.html',\r\n styleUrls: ['./app.component.css']\r\n})\r\n```\r\n\r\n```text\r\nUnexpected value 'AppComponent' declared by the module 'AppModule'. Please add a @Pipe/@Directive/@Component annotation\r\n```\r\n\r\n## Inadequate behavior\r\n\r\nBut if I write this code, the compiler will not swear\r\n\r\napp.component.ts\r\n\r\n```typescript\r\nimport { Component, Injectable } from '@angular/core';\r\n\r\nInjectable() // thats without @\r\nexport class AuthService {\r\n constructor() {\r\n\r\n }\r\n}\r\n\r\n@Component({\r\n selector: 'app-root',\r\n templateUrl: './app.component.html',\r\n styleUrls: ['./app.component.css']\r\n})\r\nexport class AppComponent {\r\n title = 'app';\r\n\r\n constructor(public auth: AuthService) {\r\n\r\n }\r\n\r\n}\r\n```\r\n\r\napp.module.ts\r\n\r\n```typescript\r\nimport { BrowserModule } from '@angular/platform-browser';\r\nimport { NgModule } from '@angular/core';\r\nimport { AppComponent, AuthService } from './app.component';\r\n\r\n@NgModule({\r\n declarations: [\r\n AppComponent\r\n ],\r\n imports: [\r\n BrowserModule\r\n ],\r\n providers: [AuthService],\r\n bootstrap: [AppComponent]\r\n})\r\nexport class AppModule { }\r\n```\r\n\r\n\r\n\r\n\r\nThat is, I am purely allowed from the beginning to write Injectable without an operator (@). So, it can lead me here:\r\n\r\n## Uncertain behavior\r\n\r\napp.component.ts\r\n\r\n```typescript\r\nimport { Component, Injectable } from '@angular/core';\r\nimport { HttpClient } from 'selenium-webdriver/http';\r\n\r\nInjectable()\r\nexport class AuthService {\r\n constructor(private http: HttpClient) {\r\n\r\n }\r\n}\r\n\r\n@Component({\r\n selector: 'app-root',\r\n templateUrl: './app.component.html',\r\n styleUrls: ['./app.component.css']\r\n})\r\nexport class AppComponent {\r\n title = 'app';\r\n\r\n constructor(private auth: AuthService) {\r\n\r\n }\r\n\r\n}\r\n```\r\n\r\napp.module.ts\r\n\r\n```typescript\r\nimport { BrowserModule } from '@angular/platform-browser';\r\nimport { NgModule } from '@angular/core';\r\nimport { HttpClientModule } from '@angular/common/http';\r\nimport { AppComponent, AuthService } from './app.component';\r\n\r\n@NgModule({\r\n declarations: [\r\n AppComponent\r\n ],\r\n imports: [\r\n BrowserModule,\r\n HttpClientModule\r\n ],\r\n providers: [AuthService],\r\n bootstrap: [AppComponent]\r\n})\r\nexport class AppModule { }\r\n```\r\n\r\n\r\n\r\n\r\n```text\r\nUncaught Error: Can't resolve all parameters for AuthService: (?).\r\n```\r\n\r\nBut I would expect from the very beginning\r\n\r\n```text\r\nUnexpected value 'AuthService' declared by the module 'AppModule'. Please add a @Injectable annotation\r\n```\r\n\r\n## The worst after\r\n\r\nThe worst thing is that if I add an immediately missed statement (@), it means that ng serve does not work properly after that.\r\n\r\n\r\n\r\n\r\n\r\n## Environment\r\n\r\nAngular version: 5.1.3\r\nBrowser: Chrome 63\r\nNode version: 8.7.0\r\nWindows 10\r\n","author":{"url":"https://github.com/splincode","@type":"Person","name":"splincode"},"datePublished":"2018-01-08T11:57:10Z","url":"https://github.com/angular/angular/issues/21382"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:90aee589-423a-19ac-aa2e-fdc49a5053cb |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C920:785A9:133E245:18689B4:6B012332 |
| html-safe-nonce | a0ecf93c9bcfa2c726735e9a1bdc5150e937151353729f9b699e7e9c1a44329c |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDOTIwOjc4NUE5OjEzM0UyNDU6MTg2ODlCNDo2QjAxMjMzMiIsInZpc2l0b3JfaWQiOiI2MTIwOTQzMzM5MTI3Nzc2MDUwIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | ea8511b50bcac6aab258667bfd3accf5d7b3da7a50ef9860a5504dd98e302e6f |
| hovercard-subject-tag | issue:286723477 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/angular/angular/21382/issue_layout |
| twitter:image | https://opengraph.githubassets.com/02df0d6500170c0413b8a10ac84cd431df0dc95e7b81cc7e666a2b082c8773f1/angular/angular/issues/21382 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/02df0d6500170c0413b8a10ac84cd431df0dc95e7b81cc7e666a2b082c8773f1/angular/angular/issues/21382 |
| og:image:alt | Adequate behavior If I write this code, the compiler will swear Component({ selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.css'] }) Unexpected value 'AppCom... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | splincode |
| hostname | github.com |
| expected-hostname | github.com |
| None | cc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c |
| turbo-cache-control | no-preview |
| go-import | github.com/angular/angular git https://github.com/angular/angular.git |
| octolytics-dimension-user_id | 139426 |
| octolytics-dimension-user_login | angular |
| octolytics-dimension-repository_id | 24195339 |
| octolytics-dimension-repository_nwo | angular/angular |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 24195339 |
| octolytics-dimension-repository_network_root_nwo | angular/angular |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 8c77c9e8439031ad54c75a250694842892f693e1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width