[英]What's wrong with my Angular 2 app (TypeScript)
I have a component EventListComponent 我有一个组件EventListComponent
import { Component } from 'angular2/core';
@Component ({
selector: 'el-events',
templateUrl: 'app/events/event-list.component.html'
})
export class EventListComponent {
pageTitle: string = 'Events List';
}
which should be rendered in AppComponent 应该在AppComponent中呈现
import { Component } from 'angular2/core';
import { EventListComponent } from './events/event-list.component';
@Component({
selector: 'events-app',
template: `
<div>
<h1>{{pageTitle}}</h1>
<el-events></el-events>
</div>`,
directives: [ EventListComponent ]
})
export class AppComponent {
pageTitle: string = 'Local Events App';
}
Directives, selectors, import/export and entire decorator is setuped correclty, IDE says. IDE说,正确设置了指令,选择器,导入/导出和整个装饰器。 Yes, I use old Angular 2 version with directives, that's a course requirements.
是的,我使用带有指令的旧Angular 2版本,这是课程的要求。
So, there's a problem - page doesn't show components. 因此,存在一个问题-页面未显示组件。 Here are errors:
错误如下:
And project tree is this: 项目树是这样的:
I discovered that error happens when I add directives , so maybe problem is here. 我发现在添加指令时发生错误,所以问题可能出在这里。 Angular version is:
角版本为:
"dependencies": {
"angular2": "2.0.0-beta.15"
}
UPD Index.html UPD Index.html
<!DOCTYPE html>
<html>
<head>
<title>Local Events App</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="node_modules/bootstrap/dist/css/bootstrap.css" rel="stylesheet" />
<link href="app/app.component.css" rel="stylesheet" />
<!-- 1. Load libraries -->
<!-- IE required polyfills, in this exact order -->
<script src="node_modules/angular2/es6/dev/src/testing/shims_for_IE.js"></script>
<script src="node_modules/es6-shim/es6-shim.min.js"></script>
<script src="node_modules/systemjs/dist/system-polyfills.js"></script>
<script src="node_modules/angular2/bundles/angular2-polyfills.js"></script>
<script src="node_modules/systemjs/dist/system.src.js"></script>
<script src="node_modules/rxjs/bundles/Rx.js"></script>
<script src="node_modules/angular2/bundles/angular2.dev.js"></script>
<!-- 2. Configure SystemJS -->
<script>
System.config({
packages: {
app: {
format: 'register',
defaultExtension: 'js'
}
}
});
System.import('app/main')
.then(null, console.error.bind(console));
</script>
</head>
<body>
<events-app>
Loading App...
</events-app>
</body>
</html>
event-list.component.html event-list.component.html
<div class 'panel panel-primary'>
<div class='panel-heading'>
{{pageTitle}}
</div>
<div class='panel-body'>
<div class='row'>
<div class='col-md-2'></div>
<div class='col-md-4'>
<input type="text" />
</div>
</div>
<div class='row'>
<div class='col-md-6'>
<h3>Search by: </h3>
</div>
</div>
</div>
<div class='table-responsive'>
<table class='table'>
<thead>
<tr>
<th>
<button class='btn btn-primary'>
Show image
</button>
</th>
<th>Event</th>
<th>Code</th>
<th>Date</th>
<th>Fee</th>
<th>Rating</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
</div>
You're missing =
in your event-list.component.html 您在event-list.component.html中缺少
=
<div class 'panel panel-primary'>
It should be 它应该是
<div class='panel panel-primary'>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.