小编Mar*_*690的帖子

模式验证中所需的 Mongoose 数组不起作用

在我的架构中,我需要有一个属性,它是一个必须始终不为空且不为未定义的数组。

所以我定义了它是必需的,但是验证并没有像我预期的那样工作,因为如果我省略了这个属性,就不会抛出任何错误。

在简单属性(不是数组)的情况下,这按我的预期工作

const nodeSchema = new Schema({
    address: { type: String, required: true },
    outputs: { type: [String], required: true }
})
Run Code Online (Sandbox Code Playgroud)

mongoose mongodb mongoose-schema

4
推荐指数
2
解决办法
1323
查看次数

Angular 2 向应用程序根组件发出事件

我想向作为我的应用程序引导程序的组件发出一个事件。该组件是 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)

所以问题是地图显示组件必须将事件发送给他的父组件

eventemitter angular2-routing angular

1
推荐指数
1
解决办法
4186
查看次数