Deliver web apps with confidence 🚀
Find a file
JoostK bc54687c7b fix(compiler-cli): exclude abstract classes from strictInjectionParameters requirement (#44615)
In AOT compilations, the `strictInjectionParameters` compiler option can
be enabled to report errors when an `@Injectable` annotated class has a
constructor with parameters that do not provide an injection token, e.g.
only a primitive type or interface.

Since Ivy it's become required that any class with Angular behavior
(e.g. the `ngOnDestroy` lifecycle hook) is decorated using an Angular
decorator, which meant that `@Injectable()` may need to have been added
to abstract base classes. Doing so would then report an error if
`strictInjectionParameters` is enabled, if the abstract class has an
incompatible constructor for DI purposes. This may be fine though, as
a subclass may call the constructor explicitly without relying on
Angular's DI mechanism.

Therefore, this commit excludes abstract classes from the
`strictInjectionParameters` check. This avoids an error from being
reported at compile time. If the constructor ends up being used by
Angular's DI system at runtime, then the factory function of the
abstract class will throw an error by means of the `ɵɵinvalidFactory`
instruction.

In addition to the runtime error, this commit also analyzes the inheritance
chain of an injectable without a constructor to verify that their inherited
constructor is valid.

BREAKING CHANGE: Invalid constructors for DI may now report compilation errors

When a class inherits its constructor from a base class, the compiler may now
report an error when that constructor cannot be used for DI purposes. This may
either be because the base class is missing an Angular decorator such as
`@Injectable()` or `@Directive()`, or because the constructor contains parameters
which do not have an associated token (such as primitive types like `string`).
These situations used to behave unexpectedly at runtime, where the class may be
constructed without any of its constructor parameters, so this is now reported
as an error during compilation.

Any new errors that may be reported because of this change can be resolved either
by decorating the base class from which the constructor is inherited, or by adding
an explicit constructor to the class for which the error is reported.

Closes #37914

PR Close #44615
2022-10-10 21:46:25 +00:00
.circleci feat(core): drop support for TypeScript 4.6 and 4.7 (#47690) 2022-10-10 16:18:56 +00:00
.devcontainer docs: fixed typos (#47008) 2022-08-01 11:15:54 -07:00
.github build: update scorecard action dependencies (#47385) 2022-10-10 20:05:23 +00:00
.husky build: remove unnecessary husky gitignore file (#42870) 2021-07-19 17:31:55 -07:00
.ng-dev build: update dev-infra packages and account for build-tooling split from ng-dev (#46976) 2022-08-02 09:37:37 -07:00
.vscode docs: initial upload of styles used by doc linter (#46897) 2022-08-01 09:29:06 -07:00
.yarn build: update to yarn v1.22.17 (#44150) 2021-11-15 11:19:05 -08:00
aio build(docs-infra): upgrade cli command docs sources to 46cb32b90 (#47703) 2022-10-10 20:04:56 +00:00
devtools feat(devtools): implement inspect functionality for directives (#47334) 2022-09-19 18:59:13 +02:00
docs docs: Add new PR response templates (#47515) 2022-09-23 14:02:03 -07:00
goldens fix(compiler-cli): exclude abstract classes from strictInjectionParameters requirement (#44615) 2022-10-10 21:46:25 +00:00
integration feat(core): drop support for TypeScript 4.6 and 4.7 (#47690) 2022-10-10 16:18:56 +00:00
modules build: update dev-infra packages and account for build-tooling split from ng-dev (#46976) 2022-08-02 09:37:37 -07:00
packages fix(compiler-cli): exclude abstract classes from strictInjectionParameters requirement (#44615) 2022-10-10 21:46:25 +00:00
scripts build: setup remote execution through shared command (#47537) 2022-10-07 09:31:30 -07:00
third_party test: remove unused intl polyfill from tests and third_party vendoring (#46512) 2022-06-27 09:03:48 -07:00
tools build: temporarily patch @bazel/concatjs to unblock tsickle update (#47018) 2022-08-03 17:36:18 -07:00
.bazelignore test: delete bazel_ngtsc_plugin integration test (#47584) 2022-09-30 10:53:04 -07:00
.bazelrc test: delete bazel_ngtsc_plugin integration test (#47584) 2022-09-30 10:53:04 -07:00
.bazelversion build: update to bazel v5 for new runfiles API used in dev-infra (#45407) 2022-03-21 16:55:36 -07:00
.clang-format feat(tooling): Add a .clang-format for automated JavaScript formatting. 2015-04-02 08:44:34 -07:00
.editorconfig build: use https link to editorconfig.org in .editorconfig (#27664) 2018-12-18 09:30:09 -08:00
.gitattributes build: cleanup .gitattributes file and remove outdated CRLF attribute (#46513) 2022-06-28 13:38:27 -07:00
.gitignore ci: fix stamping for builds performed in CI (#45147) 2022-02-25 19:14:05 +00:00
.gitmessage build: clean up references to old master branch (#45856) 2022-05-04 16:23:33 -07:00
.mailmap build: add a Git .mailmap with my new name (#19550) 2017-10-09 14:35:30 -07:00
.npmrc build: rely on engines to prevent using npm for dependency install (#41477) 2021-04-07 12:05:01 -07:00
.nvmrc build: update repository to node@16 locally (#44211) 2021-11-24 18:55:33 +00:00
.prettierrc ci: use prettier to format yml files (#42136) 2021-05-19 11:20:20 -07:00
.pullapprove.yml ci: cleanup PullApprove config file (#47611) 2022-10-06 20:04:53 +00:00
.yarnrc build: update to yarn v1.22.17 (#44150) 2021-11-15 11:19:05 -08:00
browser-providers.conf.js ci: enable Android 12 for tests on CI (#45926) 2022-05-09 11:26:10 -07:00
BUILD.bazel test: avoid test fixture affecting zone in all web tests (#46511) 2022-06-27 15:46:41 -07:00
CHANGELOG.md release: cut the v15.0.0-next.5 release 2022-10-05 08:50:18 -07:00
CHANGELOG_ARCHIVE.md docs: move old changelog entries to a separate file (#45638) 2022-04-14 15:01:21 -07:00
CODE_OF_CONDUCT.md build: update CODE_OF_CONDUCT.md to match the content of angular/.github 2022-09-15 17:26:46 +00:00
CONTRIBUTING.md docs: fix grammar issues in various markdown files (#47200) 2022-08-22 10:54:56 -07:00
gulpfile.js build: remove the unused source-map-test (#46518) 2022-06-27 15:42:43 -07:00
karma-js.conf.js build: move jasmine seed generation logic to karma config (#46798) 2022-07-12 15:54:51 +00:00
LICENSE build: bump license year (#44590) 2022-01-04 12:05:25 -08:00
package.json build: update dependency google-closure-compiler to v20221004 (#47696) 2022-10-10 16:09:15 +00:00
README.md docs(core): add circleci insights metrics widget (#46496) 2022-06-24 17:04:06 -07:00
renovate.json test: delete bazel_ngtsc_plugin integration test (#47584) 2022-09-30 10:53:04 -07:00
SECURITY.md build: update SECURITY.md to match the content of angular/.github 2022-08-30 18:14:11 +00:00
tsconfig-tslint.json refactor(devtools): run ng-dev format on angular devtools files 2022-01-26 16:35:30 -05:00
tslint.json refactor(compiler): replace most usages of getMutableClone (#47167) 2022-08-22 10:40:50 -07:00
WORKSPACE build: update io_bazel_rules_sass digest to f3874ae (#47292) 2022-09-06 09:59:21 -07:00
yarn.lock build: update dependency google-closure-compiler to v20221004 (#47696) 2022-10-10 16:09:15 +00:00
yarn.lock.readme.md build: clean up references to old master branch (#45856) 2022-05-04 16:23:33 -07:00

Angular - The modern web developer's platform.

angular-logo
Angular is a development platform for building mobile and desktop web applications
using Typescript/JavaScript and other languages.

www.angular.io

Contributing Guidelines · Submit an Issue · Blog

CI status   Angular on npm   Discord conversation

InsightsSnapshot


Documentation

Get started with Angular, learn the fundamentals and explore advanced topics on our documentation website.

Advanced

Development Setup

Prerequisites

Setting Up a Project

Install the Angular CLI globally:

npm install -g @angular/cli

Create workspace:

ng new [PROJECT NAME]

Run the application:

cd [PROJECT NAME]
ng serve

Angular is cross-platform, fast, scalable, has incredible tooling, and is loved by millions.

Quickstart

Get started in 5 minutes.

Ecosystem

angular ecosystem logos

Changelog

Learn about the latest improvements.

Upgrading

Check out our upgrade guide to find out the best way to upgrade your project.

Contributing

Contributing Guidelines

Read through our contributing guidelines to learn about our submission process, coding rules and more.

Want to Help?

Want to report a bug, contribute some code, or improve documentation? Excellent! Read up on our guidelines for contributing and then check out one of our issues labeled as help wanted or good first issue.

Code of Conduct

Help us keep Angular open and inclusive. Please read and follow our Code of Conduct.

Community

Join the conversation and help the community.

Love Angular badge

Love Angular? Give our repo a star ⬆️.