在我的架构中,我需要有一个属性,它是一个必须始终不为空且不为未定义的数组。
所以我定义了它是必需的,但是验证并没有像我预期的那样工作,因为如果我省略了这个属性,就不会抛出任何错误。
在简单属性(不是数组)的情况下,这按我的预期工作
const nodeSchema = new Schema({
address: { type: String, required: true },
outputs: { type: [String], required: true }
})
Run Code Online (Sandbox Code Playgroud) 我想向作为我的应用程序引导程序的组件发出一个事件。该组件是 websocket 连接的处理程序,我需要发送一条消息,这就是我必须发出此事件的原因。
在引导组件中,我只有<router-outlet></router-outlet>这样我无法意识到如何接收事件。
例子
应用程序组件.html
<router-outlet></router-outlet>
应用程序组件.ts
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
})
export class AppComponent {
}
Run Code Online (Sandbox Code Playgroud)
应用程序模块.ts
...
@NgModule({
...
bootstrap: [AppComponent]
})
Run Code Online (Sandbox Code Playgroud)
应用程序路由.module.ts
...
const routes: Routes = [
{ path: 'display', component: MapDisplayComponent }
];
Run Code Online (Sandbox Code Playgroud)
地图显示.components.ts
@Component({
selector: 'app-map-display',
templateUrl: './map-display.component.html',
styleUrls: ['./map-display.component.scss']
})
export class MapDisplayComponent {
@Output() sendMessage: EventEmitter<any> = new EventEmitter<any>();
}
Run Code Online (Sandbox Code Playgroud)
所以问题是地图显示组件必须将事件发送给他的父组件