Angular CLI production build doesn't allow dynamic properties on components
Versions
Angular CLI: 1.6.0
Node: 6.9.1
OS: win32 x64
Angular: 5.1.0
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, platform-server, router
@angular/cli: 1.6.0
@angular-devkit/build-optimizer: 0.0.35
@angular-devkit/core: 0.0.22
@angular-devkit/schematics: 0.0.41
@ngtools/json-schema: 1.1.0
@ngtools/webpack: 1.9.0
@schematics/angular: 0.1.10
@schematics/schematics: 0.0.10
typescript: 2.6.2
webpack: 3.10.0
Repro steps
- In constructor of a component create a property like this:
this["foo"] = "Hello" - In the template for this component create a binding like this:
{{foo}} - Perform a production build via
ng build --prod
Observed behavior
I get the error Property 'foo' does not exist on type 'BarComponent'.
Desired behavior
I understand why this type of property checking could be useful, but this prevents me from using any dynamic generation of properties of my component in my template. It would be nice to make this type of checking be optional via a build parameter or via the .angular-cli.json file. This issue is really getting in my way and stopping my progress.
Mention any other details that might be useful (optional)
Production builds default to using AOT compilation, which is where the error you see comes from. Setting dynamic properties like that is not supported in AOT compilation. You can submit a feature request for this functionality in https://github.com/angular/angular (this is the repo for the AOT compiler).
You can disable AOT in production via ng build --prod --aot=false but this is generally discouraged.
This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.