在我的app.js中,我需要我的模型
var User = require('./models/user');
app.post('/user/add', function(req,res,next){
var newUser = new User();
newUser.add(req.body.name, function(response){
res.json(response);
})
});
Run Code Online (Sandbox Code Playgroud)
我的模型(user.js)看起来像这样
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var userSchema = new Schema({
name: String
});
var User = module.exports = mongoose.model('user', userSchema);
module.exports.add = function(name,callback){
User.save({name:name}).exec(callback);
}
Run Code Online (Sandbox Code Playgroud)
但我得到newUser.add的错误不是一个函数?
您好我是用户角5,我想切换为我的soundcloud播放器更改播放< - >暂停图标.
这是我的TypeScript,后跟我的html.
我可以在我的控制台中看到我正确切换了playMode,但字体真棒图标并没有像预期的那样改变.
谢谢您的帮助.
import { Ng2DeviceService } from 'ng2-device-detector';
import { Component, OnInit } from '@angular/core';
import { NgClass } from '@angular/common';
import './soundcloud-script.js';
@Component({
selector: 'app-sc-player',
templateUrl: './sc-player.component.html',
styleUrls: ['./sc-player.component.css']
})
export class ScPlayerComponent{
playMode: boolean;
constructor(private deviceService: Ng2DeviceService)
{
this.playMode = true;
}
toggleIcon(){
this.playMode = !this.playMode;
console.log(this.playMode);
}
}Run Code Online (Sandbox Code Playgroud)
<span id="play"
(click)="toggleIcon()">
<i [ngClass]="{'fas fa-pause positionPlay': !playMode, 'fas fa-play positionPlay': playMode}"></i>
</span>Run Code Online (Sandbox Code Playgroud)
正如标题所述:PhpStorm无法识别定制的Laravel外墙.
有没有办法解决这个问题?
我有一个表单,仅当值不等于 0 时,我才想实现 MAXLENGTH 验证。
那么有parameter.valueMaxlength === 0 { then dont execute maxlength validation }
没有办法把这个逻辑写在html文件中呢。
<mat-form-field *ngSwitchCase="'TEXTBOX'" class="example-full-width">
<input
matInput
[placeholder]="parameter.displayName"
[formControlName]="parameter.id"
[id]="parameter.id"
[type]="parameter.dataType"
[maxlength] = "parameter.valueMaxlength"
/>
</mat-form-field>
Run Code Online (Sandbox Code Playgroud) forms maxlength angular angular-reactive-forms angular2-form-validation
我正在学习如何使用 getline 函数读取字符串。
我知道 getline 函数读取字符串,只要我们没有按回车键或 getline 参数中的大小值就会交叉。就我尝试 getline 函数读取一行字符串而言,我没有遇到任何问题。
但是当我试图在两个不同的字符数组中一个接一个地读取两行字符串时,我得到了我不期望的输出。要理解我的问题,请遵循以下几行
#include <iostream>
using namespace std;
int main()
{
char line1[10];
char line2[10];
cin.getline(line1,7);
cin.getline(line2,7);
cout << "\nline1 =" << line1 <<endl;
cout << "line2 =" << line2 <<endl;
}
Run Code Online (Sandbox Code Playgroud)
当我运行上面的程序时,它要求我输入,然后我将橙色作为第一个输入并按下回车按钮。
接下来它要求我提供第二个输入。然后我给了香蕉并按回车按钮。在这种情况下,它产生了我预期的结果。但是如果为第一个输入输入橙子,它不会等待我输入第二个输入。
结果 line1 存储橙色但 line2 保持空白。现在我的问题是 line1 存储橙色没有错。但我不明白为什么 line2 保持空白不应该包含 line1 接受输入后剩余的数据我的意思是 line2 不应该包含 s 作为值。
因为橙色是一个 6 位数的单词,所以 getline 将存储前六位数,然后在我设置 geline 7 的大小时添加一个空字符。
然后其他剩余的数据将在下一次调用 getline 函数时分配。所以不应该像第一次读取 new_line 字符后那样将 s 存储在 line2 中。
为什么第 2 行会保持空白,为什么在给出第一个输入后屏幕不会停止输入?
所以,我的 Angular 组件看起来像这样
<div class="hello" (keydown.enter)="doSomething()"></div>
Run Code Online (Sandbox Code Playgroud)
我正在尝试编写案例测试 - 当用户专注于 div 时,按 Enter 应该调用 doSomething()。不幸的是,我无法用旁观者来嘲笑这种情况。我已经尝试过:
spectator.focus(spectator.query('.hello'));
expect(spectator.query('.hello')).toBeFocused(); // test failed
spectator.keyboard.pressEnter();
Run Code Online (Sandbox Code Playgroud)
还
spectator.query('.hello').dispatchEvent(new Event('focus'));
Run Code Online (Sandbox Code Playgroud)
并且两者都还与
spectator.detectChanges(); // without success
Run Code Online (Sandbox Code Playgroud)
我想,这个问题出在我的 HTML 模板中,但这些函数也不适用于:
<div class="hello" tabindex="0">
Run Code Online (Sandbox Code Playgroud)
甚至与
<input class="hello" type="text">
Run Code Online (Sandbox Code Playgroud)
请给予一些支持,如何关注 div 元素,然后按 Enter 键。
我对漂亮有疑问。我正在尝试更新 Angular 项目中的更漂亮的版本。迁移到 2.0.5 版本后,prettier 看不到配置文件中的某些选项。package.json 文件中的配置如下所示:
"prettier": {
"trailingComma ": "none",
"htmlWhitespaceSensitivity": "strict",
"semi": true,
"singleQuote": true,
"printWidth": 140,
"arrowParens": "avoid",
"tabWidth": 2,
"endOfLine": "auto"
},
Run Code Online (Sandbox Code Playgroud)
不幸的是,这不起作用。当我从控制台运行 prettier 时,我收到一个错误,并且 prettier 弄乱了所有文件中的尾随逗号(我不想要它们)。
$ prettier --write --config ./package.json "src/**/*.ts" 忽略未知选项 { "trailingComma ": "none" }。您的意思是尾随逗号吗?
我怎样才能解决这个问题?
我必须使用JavaScript返回参数param min和max之间的句子中的单词数。
长度可以包括最小和最大
例如,findWordsWithLengthRange(“生活是要产生影响,而不是要收入”,6,8)返回值应等于4
下面是我尝试的功能。
function wordLengthCount(str, min, max) {
var a = str.split(' ');
var count=0;
for(var i =0; i<a.length ; i++){
if(a[i]>=min && a[i]=<max){
count += 1;
}
}
return count;
}
console.log(wordLengthCount("The weather is so good today", 2, 5));
Run Code Online (Sandbox Code Playgroud)
上面的代码的计数始终为0。上面的实际结果应该是5
在以下文字中:
"123 + 456 + 789"
如何用%20替换所有"+"字符?我看到的使用正则表达式的例子最终将+视为表达式使用的规则的一部分,因此似乎不能使用正则表达式.