2017-10-14 258 views
0

cockpit.component.ts。 。 。 ......。 。 ......。 。 。 。 ....。 。 。 。 .... ......... ....... ........。 。 ......。 .....。 ......。 。 ......。 。 ...錯誤類型錯誤:_co.onBlueprintAdded不是一個函數

import {Component, EventEmitter, OnInit, Output} from '@angular/core'; 
 

 
@Component({ 
 
    selector: 'app-cockpit', 
 
    templateUrl: './cockpit.component.html', 
 
    styleUrls: ['./cockpit.component.css'] 
 
}) 
 
export class CockpitComponent implements OnInit { 
 
    @Output() serverCreated = new EventEmitter<{serverName: string, serverContent: string}>(); 
 
    @Output() blueprintCreated = new EventEmitter<{serverName: string, serverContent: string}>(); 
 
    newServerName = ''; 
 
    newServerContent = ''; 
 
    constructor() { } 
 

 
    ngOnInit() { 
 
    } 
 
    onAddServer() { 
 
    this.serverCreated.emit(
 
     {serverName: this.newServerName, 
 
     serverContent: this.newServerContent 
 
     }); 
 
    } 
 

 
    onAddBlueprint() { 
 
    this.blueprintCreated.emit(
 
     {serverName: this.newServerName, 
 
     serverContent: this.newServerContent 
 
     }); 
 
    } 
 
}

任何人都可以解釋爲什麼我收到以下錯誤?我是一個角度初學者。

app.component.ts控制檯

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

 
@Component({ 
 
    selector: 'app-root', 
 
    templateUrl: './app.component.html', 
 
    styleUrls: ['./app.component.css'] 
 
}) 
 
export class AppComponent { 
 
    serverElements = [{ 
 
    type: 'server', 
 
    name: 'Testserver', 
 
    content: 'Just a Test!!' 
 
    }]; 
 

 

 
    onServerAdded(serverData: {serverName: string, serverContent: string}) { 
 
    this.serverElements.push({ 
 
     type: 'server', 
 
     name: serverData.serverName, 
 
     content: serverData.serverContent 
 
    }); 
 
    } 
 

 
    onBlueprintAdded(blueprintData: {serverName: string, serverContent: string}) { 
 
    this.serverElements.push({ 
 
     type: 'blueprint', 
 
     name: blueprintData.serverName, 
 
     content: blueprintData.serverContent 
 
    }); 
 
    } 
 
}
<div class="container"> 
 
    <app-cockpit 
 
    (serverCreated)="onServerAdded($event)" 
 
    (blueprintCreated)="onBlueprintAdded($event)" 
 
    ></app-cockpit> 
 
    <hr> 
 
    <div class="row"> 
 
    <div class="col-xs-12"> 
 
    <app-server-element 
 
     *ngFor="let serverElement of serverElements" 
 
     [element]="serverElement" 
 
    ></app-server-element> 
 
    </div> 
 
    </div> 
 
</div>

錯誤:

AppComponent.html:2 ERROR TypeError: _co.onBlueprintAdded is not a function 
    at Object.eval [as handleEvent] (AppComponent.html:4) 
    at handleEvent (core.es5.js:12023) 
    at callWithDebugContext (core.es5.js:13493) 
    at Object.debugHandleEvent [as handleEvent] (core.es5.js:13081) 
    at dispatchEvent (core.es5.js:8615) 
    at core.es5.js:10783 
    at SafeSubscriber.schedulerFn [as _next] (core.es5.js:3647) 
    at SafeSubscriber.__tryOrUnsub (Subscriber.js:238) 
    at SafeSubscriber.next (Subscriber.js:185) 
    at Subscriber._next (Subscriber.js:125) 

包涵仍然需要寫一些東西之前,我可以發佈問題

+0

你能否提供展示你是如何從'cockpit.component.ts' emmiting數據的一些代碼。 – Andresson

+0

我已經插入它 –

+0

你的問題標題有不同的錯誤比你的問題?這是什麼?你能否創建一個演示(plunker,stackblitz?)來展示你的問題。 – Alex

回答

1

只需要重新運行NG再次發球,它將使新的捆綁

+0

是的,那是我的問題 – 2017-12-05 22:23:05

相關問題