小编ngD*_*ugh的帖子

Angular 7 - 动态添加指令

<input  {{field.validatorDirective}} 
        class="form-control" 
        [ngClass]="{ 'border-danger': hasErrors }" 
        (keyup)="callback()" 
        [formControlName]="field.key" 
        [id]="field.key"
        [type]="field.type" 
        [placeholder]="field.placeholder" 
        [value]="field.value">
Run Code Online (Sandbox Code Playgroud)

field 具有所需的所有内容,但我想动态添加要使用的指令名称。

它目前被添加stringfield.validatorDirective

这有错误

TextComponent.html:2 错误 DOM 异常:无法在“元素”上执行“setAttribute”:“{{field.validatorDirective}}”不是有效的属性名称。

我的指令有选择器 usernameValidator

angular angular7

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

Mongoose findOneAndUpdate 当值不在数组中时

我有下面的 Mongoose 函数,我试图在其中选择 WHERE email=req.body.email并且referenceId 不在数组中。

referenceId是一个字符串数组[String],其中包含一个对象 ID 数组。

const refereeSchema = new Schema({
  firstName: {
    type: String,
    required: true
  },
  lastName: {
    type: String,
    required: true
  },
  email: {
    type: String,
    required: true,
    unique: true
  },
  referenceId: [
    {
    type: mongoose.Schema.Types.ObjectId,
    ref: 'User',
    }
  ],
  token: {
    type: String,
    required: true
  },
  password: {
    type: String
  },
  company: {
    type: String,
    required: true
  },
  role: {
    type: String,
    required: …
Run Code Online (Sandbox Code Playgroud)

mongoose mongodb node.js

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

JavaScript部分匹配数组中的字符串

const arr = ['be-', 'fe-', 'automated'];

const str = 'fe-cheese';
const oi = arr.includes(str) ? 'cheese' : 'meat';

console.log(oi);
Run Code Online (Sandbox Code Playgroud)

我有一个部分匹配的数组,我想检查字符串是否包含任何部分arr.

meat当它匹配fe-并返回时,上面返回cheese

javascript arrays ecmascript-6

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