组件没有显示在页面上
我得到了一个由另一个人开发的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; }
在my-app
的template
中,这是app/app.component.html
我把一个简单的div
来testing:
<div><h1>app components</h1></div>
运行时,我可以看到Loading.....
这是在index.html
但不是app/app.component.html
的内容。
我错过了什么?
我不能看到你是否加载angular度和你的转换ts在index.html中的任何地方。 你需要加载所有需要的依赖于运行angular2应用程序在index.html和allso你transpiled ts。
注意: – 你需要把所有的链接加载CSS基地标签。
<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"> <base href='/'>