小编elz*_*zoy的帖子

Mongoose - 推送参考 - 无法读取未定义的属性“推送”

我想添加一个类别,然后如果成功,将它的引用推送到用户的集合。这就是我这样做的方式:

那是我的“dashboard.js”文件,其中包含类别架构。

var users = require('./users');

var category = mongoose.model('categories', new mongoose.Schema({
    _id:     String,
    name:    String,
    ownerId: { type: String, ref: 'users' }
}));

router.post('/settings/addCategory', function(req, res, next) {
  console.log(req.body);
  var category_toAdd = new category();
  category_toAdd._id = mongoose.Types.ObjectId();
  category_toAdd.name = req.body.categoryName;
  category_toAdd.ownerId = req.body.ownerId;

  category.findOne({
    name: req.body.categoryName,
    ownerId: req.body.ownerId
  }, function(error, result) {
     if(error) console.log(error);
     else {
       if(result === null) {
         category_toAdd.save(function(error) {
           if(error) console.log(error);
           else {
             console.log("Added category: " + category_toAdd);
<<<<<<<<<<<<<<<<<<<THE CONSOLE LOG WORKS GOOD
             users.categories.push(category_toAdd);
           }
         }); …
Run Code Online (Sandbox Code Playgroud)

push ref undefined mongoose mongodb

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

当 select 具有 formControlName 时,选项上的“selected”标记不起作用

<div class="form-inline">\n  <label class="text-color">Lokalizacja:</label>\n  <select class="form-control dropdown" formControlName="localization">\n    <option value="Gda\xc5\x84sk" selected>Gda\xc5\x84sk</option>\n    <option value="Rzesz\xc3\xb3w">Rzesz\xc3\xb3w</option>\n    <option value="Wroc\xc5\x82aw">Wroc\xc5\x82aw</option>\n  </select>\n</div>\n
Run Code Online (Sandbox Code Playgroud)\n\n

不知道发生了什么,但在这种情况下,没有选择的选项,我必须从列表中选择一些内容。当我formControlName="localization从选择中删除时,然后Gda\xc5\x84sk在开始时被选择。

\n\n

定位控制看起来像这样localizationCtrl = new FormControl("", Validators.required);

\n\n

localizationCtrl = new FormControl("");当我将其替换为:\n \n当然下一步是通过执行以下操作将该控件添加到 OfferForm 中时没有区别:

\n\n
...\nlocalization: this.localizationCtrl\n...\n
Run Code Online (Sandbox Code Playgroud)\n\n

但请不要试图在这里寻找问题,因为我在 OfferForm 中有类似 7 个其他验证器,并且它们都工作正常。

\n

select angular

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

是否可以通过装饰器修改方法的返回类型?

假设我有一个A装饰器应用于返回字符串的方法。装饰器使用该字符串并最终返回B类型(一个类)。

class B {
  constructor(text: string) { ... }

  method() {...}
}

class X {
  @A
  someMethod(): string {
    return 'lalala';
  }
}
Run Code Online (Sandbox Code Playgroud)

装饰者

function A(target, property, descriptor) {
  const text: string = descriptor.value();

  descriptor.value = () => new B(text);
}
Run Code Online (Sandbox Code Playgroud)

发生了什么?现在someMethod返回一个B对象而不是字符串。但我不能做这样的事情:

class X {
  constructor() {
    this.someMethod().method();
  }

  @A
  someMethod(): string {
    return 'lala';
  }
}
Run Code Online (Sandbox Code Playgroud)

为什么?因为someMethod从定义中是字符串类型,但装饰器使其返回B类型。我可以以某种方式让打字稿知道someMethod实际上返回B,而不是string

decorator typescript

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

接口错误地扩展了接口

class One {\n  controls: { [key: string]: number };\n}\n\ninterface Two<T> extends One {\n  controls: { [key in keyof T]: number }\n}\n
Run Code Online (Sandbox Code Playgroud)\n\n

我收到一个错误:

\n\n
\n

TS2430: 接口\xc2\xa0\'两个\'\xc2\xa0不正确\xc2\xa0扩展\xc2\xa0接口\xc2\xa0\'一个\'。\n \xc2\xa0\xc2\xa0Types\xc2\xa0of\xc2 \xa0property\xc2\xa0\'控件\'\xc2\xa0\xc2\xa0不兼容。\n \xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0Type\xc2\xa0\'{\xc2\xa0[键\xc2\xa0in\xc2\xa0keyof\xc2\xa0T]:\xc2\xa0number;\xc2\xa0}\'\xc2\xa0is\xc2\xa0not\xc2\xa0可分配\xc2\xa0to\xc2\xa0type\xc2\ xa0\'{\xc2\xa0[键:\xc2\xa0string]:\xc2\xa0number;\xc2\xa0}\'

\n
\n\n

在打字稿游乐场(点击)中,一切似乎都很好。这是怎么回事?

\n\n

打字稿版本:2.4.2

\n

interface typescript

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

Angular2 - CKEditor使用

我如何将ckeditor与Angular2组件一起使用?

做类似的事情:

import {Component} from 'angular2/core'

@Component({
  selector: 'e',
  template: `
  <textarea name="editor1" id="editor1" rows="10" cols="80">
      This is my textarea to be replaced with CKEditor.
  </textarea>
  <script>
      CKEDITOR.replace( 'editor1' );
  </script>
  `
})

export class E {

}
Run Code Online (Sandbox Code Playgroud)

并在index.html中打印它:

<html>
  <head>
    <title>Hello</title>
    <script src="../ckeditor/ckeditor.js"></script>
    <script src="../systemjs/dist/system.src.js"></script>
    <script src="../es6-shim/es6-shim.js"></script>
    <script src="../angular2/bundles/angular2-polyfills.js"></script>
    <script src="../rxjs/bundles/Rx.js"></script>
    <script src="../angular2/bundles/angular2.dev.js"></script>
    <script src="../angular2/bundles/router.dev.js"></script>
    <script src="../angular2/bundles/http.dev.js"></script>
    <script src="http://fgnass.github.io/spin.js/spin.min.js"></script>
    <script>
      System.config({
        packages: {
          compiled: {
              format: 'register',
              defaultExtension: 'js'
          }
        }
      });
      System.import('../compiled/boot')
            .then(null, console.error.bind(console));
    </script>
  </head>
  <body>
    Hackathon …
Run Code Online (Sandbox Code Playgroud)

ckeditor angular

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

ContentChild 通过扩展抽象类

我有两个不同的组件,它们扩展了一个通用组件。

AComponent extends BaseComponent {}
BComponent extends BaseComponent {}
Run Code Online (Sandbox Code Playgroud)

第三个组件具有 ng-content。

<wrapper>
  <a-component></a-component>
  <b-component></b-component>
</wrapper>
Run Code Online (Sandbox Code Playgroud)

不幸的是,这些组件在下面的场景中不可见。

WrapperComponent {
  @ContentChildren(BaseComponent) components;
}
Run Code Online (Sandbox Code Playgroud)

我不想创建具有特定类型(Acomponent、BComponnet)的ContentChild。

children angular

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

Angular2-获取文本值的选定部分

我想创建一个简单的编辑器,例如使选定的文本加粗。

有一个具有“超级文本”值的文本区域。

现在,我选择该文本的一部分(例如“ Super”)。如何获得所选值?

<textarea (selected)=".."></textarea>
Run Code Online (Sandbox Code Playgroud)

每当我在textarea中选择某些内容时,都会调用一个函数。

<textarea (selected)="view(textarea.value)" #textarea></textarea>
Run Code Online (Sandbox Code Playgroud)

当我选择某些内容时,这将打印出整个textarea值。我只想打印那部分文本,它将被选中。怎么做?

select text angular

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

file.onload中的Typescript变量未定义

  filePhotoValue: any = "xexe";

  sendFile(file) {

    var reader = new FileReader();

    reader.onload = function (e:any) {
      console.log(this.filePhotoValue);
    };

  }
Run Code Online (Sandbox Code Playgroud)

为什么要在reader.onload控制台内"undefined"而不是用filePhotoValue xexe?没有编译错误,我想为filePhotoValue insidereader.onload 设置一些值。

variables scope undefined

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