【发布时间】:2016-12-12 21:18:23
【问题描述】:
我有一个由另一个人开发的Angular2 项目,我需要运行它。当我这样做时,使用npm start 我让服务器运行,但名为my-app 的组件未在页面上呈现。
这是index.html:
<html>
<head>
<base href='/'>
<title></title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="styles.css">
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
<link href="c3.css" rel="stylesheet" type="text/css">
</head>
<body>
<my-app>Loading......</my-app>
</body>
</html>
这是app.components.ts:
import { Component } from '@angular/core';
import { AuthenticationService } from './authentication.service';
import { Router } from '@angular/router';
@Component({
selector: 'my-app',
templateUrl: 'app/app.component.html',
styleUrls: ['app/app.component.css']
})
export class AppComponent {
title = '';
isProd:boolean;
constructor(private authenticationService: AuthenticationService, private router: Router) {
this.isProd = false;
}
在template为my-app,也就是app/app.component.html我放了一个简单的div进行测试:
<div><h1>app components</h1></div>
运行时,我可以看到index.html 中的Loading.....,但看不到app/app.component.html 的内容。
我错过了什么?
【问题讨论】:
-
检查您的控制台是否有任何错误。
-
我找不到 c3.css。
-
什么是AuthenticationService?几天前我遇到了同样的问题,我不得不在@Componet 中添加提供程序,它解决了问题(例如
providers: [AuthenticationService]) -
AuthenticationService 只是应用程序内部的一个服务。没什么。我尝试添加提供者:[AuthenticationService, Router],但问题仍然存在。