d2742cf473
In the past, @Injectable had no side effects and existing Angular code is therefore littered with @Injectable usage on classes which are not intended to be injected. A common example is: @Injectable() class Foo { constructor(private notInjectable: string) {} } and somewhere else: providers: [{provide: Foo, useFactory: ...}) Here, there is no need for Foo to be injectable - indeed, it's impossible for the DI system to create an instance of it, as it has a non-injectable constructor. The provider configures a factory for the DI system to be able to create instances of Foo. Adding @Injectable in Ivy signifies that the class's own constructor, and not a provider, determines how the class will be created. This commit adds logic to compile classes which are marked with @Injectable but are otherwise not injectable, and create an ngInjectableDef field with a factory function that throws an error. This way, existing code in the wild continues to compile, but if someone attempts to use the injectable it will fail with a useful error message. In the case where strictInjectionParameters is set to true, a compile-time error is thrown instead of the runtime error, as ngtsc has enough information to determine when injection couldn't possibly be valid. PR Close #28523 |
||
---|---|---|
.buildkite | ||
.circleci | ||
.github | ||
.vscode | ||
aio | ||
docs | ||
integration | ||
modules | ||
packages | ||
scripts | ||
third_party | ||
tools | ||
.bazelignore | ||
.bazelrc | ||
.clang-format | ||
.editorconfig | ||
.gitattributes | ||
.gitignore | ||
.mailmap | ||
.nvmrc | ||
BUILD.bazel | ||
CHANGELOG.md | ||
CODE_OF_CONDUCT.md | ||
CONTRIBUTING.md | ||
LICENSE | ||
README.md | ||
WORKSPACE | ||
browser-providers.conf.js | ||
gulpfile.js | ||
index.bzl | ||
karma-js.conf.js | ||
package.json | ||
protractor-perf.conf.js | ||
shims_for_IE.js | ||
test-events.js | ||
test-main.js | ||
tslint.json | ||
yarn.lock | ||
yarn.lock.readme.md |
README.md
Angular
Angular is a development platform for building mobile and desktop web applications using Typescript/JavaScript and other languages.
Quickstart
Changelog
Learn about the latest improvements.
Want to help?
Want to file a bug, contribute some code, or improve documentation? Excellent! Read up on our guidelines for contributing and then check out one of our issues in the hotlist: community-help.