[英]Unable to use the object with key value 'templateUrl' in angular6
I have the below object in component.ts and I am going to iterate this array in the HTML template inside ui-comp-menu. 我在component.ts中有以下对象,并且要在ui-comp-menu的HTML模板中迭代此数组。
menuObject = [{
'labels': 'Content1',
'templateUrl': 'assets/partials/sample.html',
'childrens': [],
},
{
'labels': 'Content2',
'templateUrl': 'assets/partials/sample1.html',
}];
and in the html 并在html中
<ui-comp-menu [data]="menuObject" [label]="'labels'" [url]="'routeUrl'" ></ui-comp-menu>
But while compiling I got the below error 但是在编译时出现以下错误
ERROR in ./src/app/app.component.ts ./src/app/app.component.ts中的错误
Module not found: Error: Can't resolve './assets/partials/UserAdministration.html' in 'D:\\POC_Angular_6\\lib-demo\\src\\appI
找不到模块:错误:无法解析'D:\\ POC_Angular_6 \\ lib-demo \\ src \\ appI中的'./assets/partials/UserAdministration.html'
If i change the object key 'templateUrl' to some other name like 'templatePath' issue won't come and compiled successfully. 如果我将对象键'templateUrl'更改为其他名称,例如'templatePath',则问题不会成功编译。 But i am not sure about previous angular versions.
但是我不确定以前的角度版本。
This is a bug from the angular-cli
package. 这是
angular-cli
软件包中的错误。 When you check the source code
you can see that they are parsing the entire .ts file and subtracting any object in there. 当您检查
source code
您会看到它们正在解析整个.ts文件并减去其中的任何对象。 Then they are checking if there is an object with a templateUrl
or styleUrls
key in there. 然后,他们正在检查其中是否存在带有
templateUrl
或styleUrls
键的对象。
This seems a bit erratic, and could be done more properly. 这似乎有些不稳定,可以更适当地完成。 For instance to check if the subtracted object is inside an annotation (
@Component
). 例如,检查被减去的对象是否在注释(
@Component
)内。
Couple things you can do here: 您可以在这里做几件事情:
templateUrl
definitions inside your typescript file. templateUrl
定义。 Connecting to the API and removing those from your code should be enough.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.