gpt4 book ai didi

angular - 错误类型错误 : _co. onBlueprintAdded 不是函数

转载 作者:行者123 更新时间:2023-12-01 14:30:49 27 4
gpt4 key购买 nike

驾驶舱.component.ts 。 . . …… . …… . . . ..... . . ..... ...... ...... ...... ....... . ………… …… …… . …… . ...

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
});
}
}

谁能解释为什么我会收到以下错误?我是 Angular 的初学者。

应用程序组件.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)

请耐心等待我在发布问题之前还需要写一些东西

最佳答案

只需再次运行 ng serve,它就会生成新的 Bundle

关于angular - 错误类型错误 : _co. onBlueprintAdded 不是函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46739625/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com