【问题标题】:can't understand Angular 2看不懂 Angular 2
【发布时间】:2017-09-21 12:53:48
【问题描述】:

Angular 2 一直显示“应用程序正在运行”,但即使我从 VSCode 编辑器中清除代码,它也能正常工作。

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

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

}

此导航栏也不起作用。

【问题讨论】:

    标签: angular angular2-template


    【解决方案1】:

    如果没有任何其他信息,您似乎没有为组件的元数据提供选择器。选择器在应用程序的 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 {
        // ...
    

    【讨论】:

    • 非常感谢!!
    猜你喜欢
    • 2019-12-20
    • 1970-01-01
    • 2015-08-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-01
    相关资源
    最近更新 更多