如果问题很简单,请原谅我。我刚开始学习角度。
我正在尝试我的第一个应用程序。但它不编译。因为它不能识别我代码的一部分。
我在想是否有人能给我一些提示,告诉我这里做错了什么?
app.component.html文件:
<!--The whole content below can be removed with the new code.-->
<div style="text-align:center">
<h1>
Welcome to {{pageTitle}}!!
</h1>
... Starter Files ...
</div>
app.component.ts文件
import { Component } from '@angular/core';
@Component({
selector: 'pm-root',
template: <div><h1>{{pageTitle}}</h1></div> // **this line of code created error**
})
export class AppComponent {
pageTitle: string = 'Angular: Getting Started';
}
应用模块.ts
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
索引文件
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Acme Product Management</title>
<base href="/">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="favicon.ico">
</head>
<body>
<pm-root></pm-root>
</body>
</html>
错误如下:
你能帮我解决这个问题吗?
最佳答案
模板中没有反勾号或引号:
模板是ecmascript 2015 backticks中的多行字符串
(). The backtick (
)-与单个字符不同
引号(')-允许您在多行上组成一个字符串,它
使html更具可读性。
import { Component } from '@angular/core';
@Component({
selector: 'pm-root',
template: `<div><h1>{{pageTitle}}</h1></div>` // **added backticks**
})
export class AppComponent {
pageTitle: string = 'Angular: Getting Started';
}
关于angular - 模块解析失败:您可能需要适当的加载程序来处理此文件类型,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/46288014/