Angular 2 - zone.js:355未处理的承诺拒绝:模板解析错误:' stock'不是一个已知的元素:

时间:2016-10-03 04:11:15

标签: javascript node.js angular typescript

通过Udemy课程和#34; Ultimate Angular 2 Developer with Bootstrap 4&打字稿" (https://www.udemy.com/ultimate-angular-2/learn/v4/overview)并且应用程序遇到问题,因为它被困在"正在加载"并产生控制台错误,请参阅以下详细信息......

在第4节,第16讲"使用组件"它给出了如何创建" Stocks"零件。然而,在完成课程然后启动应用程序后,它会停留在"正在加载"并在浏览器控制台中给出以下错误。

Unhandled Promise rejection: Template parse errors:
'stocks' is not a known element:
1. If 'stocks' is an Angular component, then verify that it is part of this module.
2. If 'stocks' is a Web Component then add "CUSTOM_ELEMENTS_SCHEMA" to the '@NgModule.schema' of this component to suppress this message. ("
</h1>

[ERROR ->]<stocks>
</stocks>
"): AppComponent@4:0 ; Zone: <root> ; Task: Promise.then ; Value: Error: Template parse errors:(…) Error: Template parse errors:
'stocks' is not a known element:
1. If 'stocks' is an Angular component, then verify that it is part of this module.
2. If 'stocks' is a Web Component then add "CUSTOM_ELEMENTS_SCHEMA" to the '@NgModule.schema' of this component to suppress this message. ("
</h1>

[ERROR ->]<stocks>
</stocks>
"): AppComponent@4:0
    at TemplateParser.parse (http://localhost:4200/main.bundle.js:15261:19)
    at RuntimeCompiler._compileTemplate (http://localhost:4200/main.bundle.js:33578:51)
    at http://localhost:4200/main.bundle.js:33501:83
    at Set.forEach (native)
    at compile (http://localhost:4200/main.bundle.js:33501:47)
    at ZoneDelegate.invoke (http://localhost:4200/main.bundle.js:64835:28)
    at Zone.run (http://localhost:4200/main.bundle.js:64728:43)
    at http://localhost:4200/main.bundle.js:65094:57
    at ZoneDelegate.invokeTask (http://localhost:4200/main.bundle.js:64868:37)
    at Zone.runTask (http://localhost:4200/main.bundle.js:64768:47)
Error: Uncaught (in promise): Error: Template parse errors:(…)

由于我还在学习Angular,我并不完全熟悉错误,也不确定在哪里查看,Google搜索不会显示太多。我想知道该课程是否可能与更新版本的node&amp;也许是吗?

与该应用相关的文件是:

stocks.component.ts

import {Component} from '@angular/core'

@Component({
    selector: 'stock',
    template: '<h1>Stocks</h1>'
})

export class StocksComponent{

}

app.component.ts

import { Component } from '@angular/core';
import { StocksComponent } from './stocks.component';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  title = 'Woo Hoo';
}

app.component.html

<h1>
  {{title}}
</h1>

<stocks>
</stocks>

app.module.ts

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { HttpModule } from '@angular/http';

import { AppComponent } from './app.component';
import { MutualfundsComponent } from './mutualfunds/mutualfunds.component';
import { StocksComponent } from './stocks.component';

@NgModule({
  declarations: [
    AppComponent,
    MutualfundsComponent,
    StocksComponent
  ],
  imports: [
    BrowserModule,
    FormsModule,
    HttpModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

该应用程序非常基本,因此在此阶段看到此错误令人惊讶。任何帮助或指示赞赏。

1 个答案:

答案 0 :(得分:5)

问题在于选择器

stocks.component.ts

<h1>
  {{title}}
</h1>

<stock>                                        //<<<=== stock(not stocks)
</stock>

<强> app.component.html

data = LOAD 'xademo.customer_details' USING org.apache.hive.hcatalog.pig.HCatLoader();
data = FOREACH data GENERATE region, (float)balance;
groups = GROUP data BY region;
avgs = FOREACH groups GENERATE data.region, AVG(data.balance);
DUMP avgs;