【问题标题】:Unexpected value 'ProductListComponent' declared by the module 'AppModule'模块“AppModule”声明的意外值“ProductListComponent”
【发布时间】:2017-04-18 06:07:49
【问题描述】:

我是 Angular 的新手,在学习 Pluralsight 的 Angular 2 教程时被卡住了。

我有几个问题:

  • 在运行 npm start 时显示 'app/products/product-list.component.ts(6,3):错误 TS1146: 预期声明。'
  • 控制台显示以下内容,意外值 由模块“AppModule”声明的“ProductListComponent”

以下是代码文件。任何帮助,将不胜感激。

app.component.ts

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

@Component({
    selector: 'pm-app',
    template: `
        <div>
            <h1>{{pageTitle}}</h1>
            <pm-products></pm-products>
        </div>
    `
})
export class AppComponent { 
    pageTitle: string = "Acme Product Management";
}

product-list.component.ts

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

@Component({
    selector: 'pm-products',
    templateUrl: 'app/products/product-list.component.html'
});

export class ProductListComponent {

}

app.module.ts

import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';

import { AppComponent }  from './app.component';
import { ProductListComponent } from './products/product-list.component';

@NgModule({
  imports: [ BrowserModule ],
  declarations: [ 
    AppComponent, 
    ProductListComponent ],
  bootstrap: [ AppComponent ]
})
export class AppModule { }

product-list.component.html

<div class='panel panel-primary'>
    <div class='panel-heading'>
        Product List
    </div>

    <div class='panel-body'>
        <div class='row'>
            <div class='col-md-2'>Filter by:</div>
            <div class='col-md-4'>
                <input type="text" />
            </div>
        </div>
        <div class='row' >
            <div class='col-md-6'>
                <h3>Filtered by:</h3>
            </div>
        </div>

        <div class='table-responsive'>
            <table class='table'
                <thead>
                    <tr>
                        <th>
                            <button class='btn btn-primary'>
                                Show Image
                            </button>
                        </th>
                        <th>Product</th>
                        <th>Code</th>
                        <th>Available</th>
                        <th>Price</th>
                        <th>5 Star Rating</th>
                    </tr>
                </thead>
                <tbody>

                </tbody>
            </table>
        </div>
    </div>
</div>

Screenshot of the console

谢谢!

【问题讨论】:

    标签: angular


    【解决方案1】:

    你的@Component 装饰器末尾有一个;,删除它:-)

    【讨论】:

    • 知道这一切都是由于分号造成的,我很伤心。谢谢大佬帮忙,加油! :)
    猜你喜欢
    • 2016-12-24
    • 2018-04-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-16
    • 1970-01-01
    • 2017-10-03
    • 2018-11-10
    • 2021-08-15
    相关资源
    最近更新 更多