我对Angular很新,来自React.js背景.
我做了一个简单的网格组件,如下所示:
grid.component.js
import { Component, OnInit, Input } from '@angular/core';
@Component({
selector: 'app-grid',
template: `
<div [ngStyle]="styles()" [ngClass]="passClass">
<ng-content></ng-content>
</div>
`,
styles: [`
div {
display: flex;
}
`]
})
export class GridComponent implements OnInit {
@Input() direction: string;
@Input() justify: string;
@Input() align: string;
@Input() width: string;
@Input() passClass: string;
constructor() { }
ngOnInit() {
}
styles() {
return {
'flex-direction': this.direction || 'row',
'justify-content': this.justify || 'flex-start',
'align-items': this.align || 'flex-start',
...(this.width && { width: this.width }) …Run Code Online (Sandbox Code Playgroud)我构建了一个架构,如下所示:
const UserInfoSchema = new Schema({
email: { type: String, required: true, unique: true },
username: { type: String, required: true, unique: true },
userId: { type: Schema.Types.ObjectId, ref: 'User'},
displayName: { type: String, required: true },
profilePic: {
filename: {type: String},
url: {type: String}
},
created_at: Date,
updated_at: Date
})
Run Code Online (Sandbox Code Playgroud)
我这里需要的是,一旦保存了电子邮件、用户名和用户 ID 等字段,就不应该修改。猫鼬中是否有针对此类功能的预构建内容?
我已经做了一些研究schema.pre('update', (next) => {}),但没有得到任何真正有用的东西/不知道是否可以使用上述功能。非常感谢有关此事的任何帮助。提前致谢。