小编Man*_*dia的帖子

NodeJS(ExpressJS)未处理拒绝TypeError:回调不是函数

这几天我一直在学习使用Angular 6NodeJS(使用ExpressJS).为此,我决定使用Angular 6创建一个前端(其中包含一个表单),旨在通过使用我使用NodeJS创建的API 来回传递信息到我的PHPMyAdmin数据库.正如您在标题中看到的那样,当我尝试提交表单信息时出现以下错误:

" 未处理的拒绝TypeError:回调不是函数 "

我用于后期操作的代码来自另一个功能相似的API,数据库接收到question_id和user_id,但不会注册问题答案(这是最终目标).如果没有更多的东西,这里是获取和发布的代码:

const config = require('../config/config');
const knex      = config.db.knex;
const async     = require('async');


class TestModel {        
  getQuestions(callback) {
        knex('question')
        .select('id', 'libelle')
    .orderBy('id', 'asc')
        .then((data) => {
            callback(data);
        });
    }


  addResponse(reponse, callback) {
      knex('reponse')
      .insert({
          id_user : 1,
          id_question : reponse.id,
          libelle: reponse.answer,
      }).then((data) => {
          callback(data);
        });
  }        
}


module.exports = new TestModel();
Run Code Online (Sandbox Code Playgroud)

其余部分如下:

app.post('/quiz', function(req, res, next){
    var answers = …
Run Code Online (Sandbox Code Playgroud)

javascript database node.js express angular

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

如何在golang中轻松编辑JSON类型(如Node.js)

我尝试将 node.js 代码转换为 golang 代码。

这是我的示例 JSON。

{
  "result": {
    "birthInfo": {
      "birthYmd": "2018-07-25",
      "cattleNo": "cow001",
      "docType": "registerBirth",
      "lsTypeNm": "redbull",
      "monthDiff": "2018-07",
      "nationNm": "japan",
      "regType": "directly",
      "regYmd": "2018-07-25",
      "sexNm": "farm001"
    },
    "breed": {
      "dead": {
        "deadCd": "deadcd20180725",
        "deadYmd": "2018-07-25",
        "docType": "reportDeCattle"
      },
      "earTag": {
        "docType": "reattachEartag",
        "flatEartagNo": "eartag206015",
        "rfidNo": "rfid234234"
      }
    }
  }
}  
Run Code Online (Sandbox Code Playgroud)

使用node.js时,可以很容易地获取或访问这样的json数据。

let cowbytes = await stub.getState("cow001");
var cowInfo = JSON.parse(cowbytes);

var eartag = {
  docType: 'reattachEartag',
  flatEartagNo: "eartag206015",
  rfidNo: "rfid234234",
};

if (cowInfo.breed) {
  cowInfo.breed['earTag'] = …
Run Code Online (Sandbox Code Playgroud)

json go node.js hyperledger-fabric

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

events.js:167 throw er; //未处理的“错误”事件

Error: ENOSPC: no space left on device, watch '/home/me/Desktop/Edu/Web/JS/React/weather_app/public'
Run Code Online (Sandbox Code Playgroud)

我的HDD上有700gb以上的可用空间,所以不要认为这与错误有关。

错误发生后,它将无法'npm start'在我的计算机上存在的任何项目上运行。

今天,我开始做我的项目,昨天晚上我以完美的工作状态离开了我的项目。我想添加redux到我的React项目中。我所做的步骤是:

  1. 初始化本地git存储库并提交关键重要性文件

  2. 通过npm下载redux和react-redux软件包

  3. npm start-麻烦开始了

作业系统:ubuntu 16.04 LTS

Node.js版本:10.7.0

npm版本:6.2.0

我也尝试了在GitHub上建议的几个选项,这个=> 链接

error-handling node.js npm reactjs

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

如何使通用 SSR 的 Angular 应用程序使用来自 json 文件的动态配置?

我的任务是在应用程序启动期间从服务器上的 JSON 文件为 Angular 应用程序动态加载设置。特殊之处在于应用程序使用 Universal 的服务器渲染。我尝试使用此方法为浏览器执行此操作。 https://juristr.com/blog/2018/01/ng-app-runtime-config 但它仅适用于浏览器应用程序渲染。服务端渲染怎么做?

javascript kubernetes angular

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

Angular 4中的ng-repeat开始和结束

我嵌套了ng-repeat来构造可折叠网格。需要在Angular 4中实现相同的功能。在* ngFor中找不到解决方案。我使用ugug js实现的示例代码。

<table width="100%" class="table-condensed responsive-table">
<tr class="panel-heading bgOrg">
    <th class="text-right th-font">&nbsp;</th>
    <th class="text-right th-font">VMs</th>
    ..
</tr>
<tr ng-if="!departments.length" >
    <td colspan="15" class="text-center">No records Found</td>
</tr>
<tr ng-repeat-start="department in departments">
    <td class="table-white-space">
        <div class="handpointer glyphicon glyphicon-chevron-right" data-ng-click="department.show = !department.show;collapse($event)" data-target="#view_{{department.departmentid}}" data-toggle="collapse" 
            aria-expanded="false" 
            data-ng-if="department.environment!=null && !department.show">
        </div>
        <div class="handpointer glyphicon glyphicon-chevron-down" data-ng-click="department.show = !department.show;collapse($event)" data-target="#view_{{department.departmentid}}" data-toggle="collapse" 
            aria-expanded="false" 
            data-ng-if="department.environment!=null && department.show">
        </div>
        <span class="row-label"> <b ng-bind="department.name"></b> </span>
    </td>
    ..
</tr>
<tr ng-repeat-start="item in department.environment" ng-if="department.show">
    ..
</tr>
<tr ng-repeat-start="cItem in …
Run Code Online (Sandbox Code Playgroud)

angular

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

无法使用 fs.removeSync() 删除文件

我正在使用 angular 6。我想为此从后端文件夹中删除多个文件,我正在使用,fs.removeSync()但它为我提供了以下例外情况。有人能帮我吗?

“UnhandledPromiseRejectionWarning: TypeError: fs.removeSync 不是一个函数”

我的代码:

fs.removeSync('/NodeWorkspace/uploads/output/*.csv');
Run Code Online (Sandbox Code Playgroud)

node.js angular

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

subject.subscribe 未在 ngOnInit 中触发

我已经在我的service.ts中定义了主题 ,onEditItem()其中detail.component.ts传递了 id 的值,并且在new.component.ts.next()中订阅了主题 ,但订阅不起作用。订阅是在new.component.ts 中完成的ngOnInit

id 值传入成功,onEditItem()但订阅失败。我尝试在订阅内进行 console.log 检查。但控制台中没有打印任何内容。

details.component.html中

<a class="btn btn-primary" (click)="onEditItem()" routerLink="/new">Edit</a>
Run Code Online (Sandbox Code Playgroud)

详细信息.component.ts中

  onEditItem(){this.contactService.startedEditing.next(this.id);}
Run Code Online (Sandbox Code Playgroud)

contactService.ts中

export class ContactService {
  startedEditing =new Subject<number>();
}
Run Code Online (Sandbox Code Playgroud)

new.component.ts中

ngOnInit() {
  this.subscription = this.contactService.startedEditing.subscribe(
    (index: number) => {
      console.log(index);

      this.editedItemIndex = index;
      console.log(this.editedItemIndex);
      this.editMode = true;
      this.editedItem = this.contactService.getContacts(index);

      this.editForm.setValue({
        name: this.editedItem.name,
        address: this.editedItem.address
      })
    }
  );
} 
Run Code Online (Sandbox Code Playgroud)

我预计中定义的表单new.component.html应使用详细信息组件中的值进行初始化,但订阅在 中不起作用ngOnInit

observable subject-observer behaviorsubject angular2-observables angular

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

角度材料自动完成可防止 setValue 的反应性工作

编辑:用 Jojofoulk 的评论解决。

当使用 angular-material 的自动完成组件时,我试图使用setValue输入表单,但它的[matAutocomplete]属性阻止setValue在输入中显示。

检查反应式控件会发现该值是正确的,删除[matAutocomplete]它可以使其工作,但它只是没有显示出来。

<mat-list-item role="listitem" *ngFor="let skill of curObj.skills;index as ind">
  <div>
    <mat-form-field>
      <input type="text" placeholder="choose skill" aria-label="Number" matInput [formControl]="skill.control" [matAutocomplete]="auto">
      <mat-autocomplete #auto="matAutocomplete" [displayWith]="displayFn" (optionSelected)="optSel($event.option.value,skill)">
        <mat-option *ngFor="let option of skill.filteredOptions | async" [value]="option">
          {{option.name}}
        </mat-option>
      </mat-autocomplete>
    </mat-form-field>
  </div>
</mat-list-item>
Run Code Online (Sandbox Code Playgroud)
skill.control.setValue("some new value");
Run Code Online (Sandbox Code Playgroud)

autocomplete setvalue angular-material angular angular-reactive-forms

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

如何使用 Angular 和 Moment 获取下个月的第一天

我们的应用程序生成的日志存在问题。解决方案是我们需要获取下个月的第一天,即使所选的日期是月中。

尝试阅读 Moment 上的文档,但找不到任何可能的解决方案。

var currentDate = new Date();
var start_date = new Date(); //Wed Jun 05 2019 13:23:06 GMT+0800 (Philippine Standard Time)

console.log(start_date);

start_date.setDate(start_date.getDate() - 365); //1496640186958

console.log(start_date.setDate(start_date.getDate() - 365)); //Monday, June 5, 2017 1:23:06.958 PM GMT+08:00
// this output should be July 1, 2017, how can I get the first day of next month here?

start_date = customizeDate.formatDateToString(start_date);
var end_date = dateRange.endDate;
Run Code Online (Sandbox Code Playgroud)

momentjs angular

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

升级到V8后,@ ViewChild('tTaskTeam',{阅读:MatAutocompleteTrigger})无法正常工作

嗨,我今晚将项目从V7升级到了V8,阅读@viewChild时遇到了很多错误,这是由于他们进行了新的更新。我在所有@viewChild中都添加了{static:true},但随后遇到了我设置如下的这些触发器:

 @ViewChild('tTaskTeam', { read: MatAutocompleteTrigger }) autoCompleteForTaskTeamTrigger: MatAutocompleteTrigger;
  @ViewChild('tofficeUser', { read: MatAutocompleteTrigger }) officeUsersautoCompleteInputTrigger: MatAutocompleteTrigger;
  @ViewChild('recipientType', { read: MatAutocompleteTrigger })  recipientTypeTrigger: MatAutocompleteTrigger;
Run Code Online (Sandbox Code Playgroud)

viewChild只接受两个参数,我不能添加三个。因此,我读了:MatautocompleteTrigger出去,它破坏了我要执行的自动完成功能。

这是我收到的错误消息:

类型'{的参数为:typeof MatAutocompleteTrigger; }'不可分配给'{read ?: any; 静态:布尔值;}'。类型'{缺少属性'static',读取:typeof MatAutocompleteTrigger; }”,但类型为“ {必读?:任何;静态:布尔值;}'。ts(2345)core.d.ts(8066,9):此处声明为“静态”。

我添加了这些触发器,以在用户输入非所选选项列表中的字符时触发。因此它将清除并向用户显示一条消息,让他们再次选择。

这是完整的实现: HTML

<mat-form-field appearance="outline" class="task-info-form-field">
  <input tab-directive #tTaskTeam matInput (keyup.enter)="chooseFirstOption(autoCompleteForTaskTeam)" [matAutocomplete]="autoCompleteForTaskTeam" formControlName="tTaskTeam" matTooltip="You can search and it will try to autocomplete the name for you!" placeholder="Select Group">
  <mat-autocomplete #autoCompleteForTaskTeam='matAutocomplete' [displayWith]="displayTeamName">
    <mat-option class="matAutoCompleteSelect" *ngFor="let user of filteredOptions | async" [value]="user">
      <span>{{ user.TeamName }}</span> …
Run Code Online (Sandbox Code Playgroud)

upgrade angular angular7 angular8

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