我得到了一个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>
当运行这个我可以看到Loading.....
这是在index.html
但不是app/app.component.html
的内容。
我错过了什么?
检查您的控制台是否有任何错误。 –
我找不到c3.css。 – Eddy
什么是AuthenticationService?我几天前遇到了同样的问题,我不得不在@Componet中添加提供者,并且解决了问题(例如'providers:[AuthenticationService]') –