2017-04-24 46 views
-5

Angular 2一直显示“App is working”,但即使清除VSCode编辑器中的代码,它也能正常工作。无法理解Angular 2

import { Component } from '@angular/core'; 

@Component({ 
selector: '', 
templateUrl: './navbar.component.html', 
styleUrls: ['./app.component.css'] 
}) 
export class AppComponent { 

} 

此导航栏不工作。

回答

0

没有任何附加信息,它看起来像你还没有给组件的元数据选择器。选择器在应用程序的index.html文件中标识匹配的HTML元素以插入组件的HTML。

一个例子: 的index.html

<!doctype html> 
<html> 
<head> 
    <meta charset="utf-8"> 
    <title>My App</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> 
    <app-root>Loading...</app-root> // <-- OUR SELECTOR ELEMENT 
</body> 
</html> 

app.component.ts

@Component({ 
    moduleId: module.id, 
    selector: 'app-root', // <-- MATCHING SELECTOR 
    templateUrl: './app.component.html', 
    styleUrls: ['./app.component.css'], 
}) 


export class AppComponent { 
    // ... 
+0

太感谢你了! –