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:68977f6a-1b6b-bf9a-5e4f-45f5f9519939 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | EC56:2AAD2E:1A66B57:23358B6:6B015A65 |
| html-safe-nonce | c66a6dd3b60c0ffe17f3589e8e5f914d6009ed47dd71fcc85de4181e6222548f |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFQzU2OjJBQUQyRToxQTY2QjU3OjIzMzU4QjY6NkIwMTVBNjUiLCJ2aXNpdG9yX2lkIjoiMjIwNjUwNjM4MzE2MjAzODg4NSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 7ac4c64f0df75f5b8f4e6c996022ea115d21ec01f0e42aa7dd483812f5f50f62 |
| 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