angular: ERROR in templateUrl must be a string in Angular 9.0.0-rc.3
š bug report
Is this a regression?
Yes, the previous version in which this bug was not present was: 8.2.14Description
This error appears at templateUrl
. Although I fixed it with template: require(template + '')
but the error still exists.
export class DynamicListService {
addComponent(name, template: string) {
@Component({
selector: "app-tmp-" + name,
templateUrl: (template + '')
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
})
š„ Exception or Error
ERROR in templateUrl must be a string
š Your Environment
Angular Version:
Angular CLI: 9.0.0-rc.3
Node: 13.0.1
OS: win32 x64
Angular: 9.0.0-rc.3
... animations, cli, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router, service-worker
Package Version
------------------------------------------------------------
@angular-devkit/architect 0.900.0-rc.3
@angular-devkit/build-angular 0.900.0-rc.3
@angular-devkit/build-optimizer 0.900.0-rc.3
@angular-devkit/build-webpack 0.900.0-rc.3
@angular-devkit/core 9.0.0-rc.3
@angular-devkit/schematics 9.0.0-rc.3
@angular/cdk 8.2.3
@angular/material 8.2.3
@angular/material-moment-adapter 8.2.3
@ngtools/webpack 9.0.0-rc.3
@schematics/angular 9.0.0-rc.3
@schematics/update 0.900.0-rc.3
rxjs 6.5.3
typescript 3.6.4
webpack 4.41.2
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 2
- Comments: 23 (13 by maintainers)
@cocolink021195 What I can see and understand till the moment doesnāt block you to create some general component (+ some type dynamic styling, probably using CSS custom properties), which allows you to satisfy your customerās needs. All without the necessity of processing dynamic HTML code.
You need to re-think the whole thing in a more abstract way and create a general interface that allows you to cover the combination on the customersā side and keep the necessary level of integration on your backend. Such an interface offers your customers UI tools/widgets for creating a full spectrum of different list layouts but still covered by a small number of Angular key components (+ internal directives, pipes, ā¦). Itāll be with some limits, of course, but still very broad for any of your customers.
Again, you are still talking a lot about
ListComponent
but I donāt think thatās your key problem. The problem is, that you are mentally fixed to the idea of hundreds of standalone templates (probably on the base of your previous background).Customersā requests are one thing but on the other side, you have to be able to abstract those requests to the usable and functional solution. I am not sure what you want to reach. Without Angular compiler in run-time, you canāt compile HTML code together with components, directives and so. And if you inject it, you have a problem with performance, security, testing, and so on.
@DenysVuika @mlc-mlapis Haiz. I understand your comment. But that only applies to regular projects. Again, my project has hundreds of
ListTemplate
and customers can edit thetemplate
ofList
to their liking. Ex: Image 1 Image 2 You canāt create hundreds ofListComponent
and then modify it according to customer needs. Because many customers use the software, you cannot fix it for each customer and if you do, each software upgrade is a nightmare. You also canāt useinnerHTML
becauseListComponents
needs to useComponents
,Directives
,Pipes
. I thought you would think of usingjavascript
but that was terrible. Currently, my project compiles with production AOT. Andfile.html
oftemplateUrl: (template + '')
I have my own security measures. I think that if you tell your boss that you canāt do it according to the customerās request because as your comment above, I think youāre a bad developer.@mlc-mlapis yes, I fully agree. I am personally against the whole idea of having 1000 list components compiled at runtime. I would go either introducing some notation/configuration to build the list dynamically based on column schema (pretty easy) or in the worst case, having a tool to generate components at a build stage.
Thank you very much, your support is greatly appreciated. Now I know that Angular will not support this feature. I should find another framework.
@cocolink021195 In my opinion, you should have 1 component that dynamically changes its content (an so has single template/templateUrl), rather than hundreds of dynamically generated components. But itās your call anyway.
@cocolink021195 Where did you see, that syntax like
templateUrl: (template + '')
is available to use?