Angular6 Angular 6未能编译
示例:t这是应用程序组件的子组件,使用命令行 ng g c emp 创建它。任何创建它的东西都会在编译时失败 时间Angular6 Angular 6未能编译,angular6,Angular6,示例:t这是应用程序组件的子组件,使用命令行 ng g c emp 创建它。任何创建它的东西都会在编译时失败 时间 import { Component, OnInit } from '@angular/core'; @Component({ selector: 'app-emp', templateUrl: ` <h2>EmpList</h2> <ul *ngFor="let emp of empA
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-emp',
templateUrl: `
<h2>EmpList</h2>
<ul *ngFor="let emp of empArr">
<li>{{emp.name}} {{emp.id}} {{emp.age}}</li>
</ul>
`,
styleUrls: ['']
})
export class EmpComponent implements OnInit {
public empArr=[
{"id":1,"name":"jamal","age":25},
{"id":2,"name":"yasser","age":80},
{"id":3,"name":"zolla","age":11}
];
constructor() { }
ngOnInit() {
}
}
从'@angular/core'导入{Component,OnInit};
@组成部分({
选择器:“应用程序emp”,
模板URL:`
雇主
- {{emp.name}{{emp.id}{{emp.age}}
`,
样式URL:['']
})
导出类EmpComponent实现OnInit{
公营企业=[
{“id”:1,“name”:“jamal”,“age”:25},
{“id”:2,“name”:“yasser”,“age”:80},
{“id”:3,“name”:“zolla”,“age”:11}
];
构造函数(){}
恩戈尼尼特(){
}
}
我收到以下错误消息:
> Module not found: Error: Can't resolve './
> <h2>EmpList</h2>
> <ul *ngFor="let emp of empArr">
> <li>{{emp.name}} {{emp.id}} {{emp.age}}</li>
> </ul>
> ' in 'D:\Angular\bind\src\app\emp'
> ERROR in ./src/app/emp/emp.component.ts
> Module not found: Error: Can't resolve './' in 'D:\Angular\bind\src\app\emp'
>未找到模块:错误:无法解析'/
>雇主
>
>- {{emp.name}{{emp.id}{{emp.age}
>
>'在'D:\Angular\bind\src\app\emp'中'
>./src/app/emp/emp.component.ts中出错
>找不到模块:错误:无法解析“D:\Angular\bind\src\app\emp”中的“/”
由于您提供了一个内联模板,因此组件装饰器中的templateUrl
属性应改为template
或者,将模板放在一个单独的文件中,然后您可以通过URL引用它。您需要在
emp.component.ts
文件中进行更改
Angular 6以2种方式提供模板注入
雇主
- {{emp.name}{{emp.id}{{emp.age}}
,
样式URL:['']
})我认为这将明确
templateUrl
和template
之间的概念和区别,您正在向templateUrl提供html
基本上,从@component
中的angular2开始,构造函数对象几乎没有component.html链接的属性
templateUrl
:这里我们提供component.html的相对路径
文件李>
模板
:这里我们提供组件中使用的html