有没有办法只记录对我的 Nodejs 服务器的每次调用。字面意思就是调用的 URL。我知道这是可能的,因为我曾经在教程中看到过一个超级快速的示例,但我不知道在哪里看到它。
这是我正在寻找的一个糟糕的例子:
app.listen(port, (call)=>{
console.log(call);
console.log(`Server running on http://localhost:${port}...`);
})
Run Code Online (Sandbox Code Playgroud) 我需要一些帮助来理解如何在datalistAngular 中使用 HTML 。我这里有个对象。我希望下拉菜单显示make and model汽车。但是当您选择 a 时car,selectedCar变量应该是整个汽车对象。但是input应该仍然只显示make and model.
cars = [{
make: 'Ford',
model: 'GTX',
color: 'green'
}, {
make: 'Ferarri',
model: 'Enzo',
color: 'red'
}, {
make: 'VW',
model: 'Amarok',
color: 'white'
}]
...
<input list="id-car" [(ngModel)]="selectedCar">
<datalist id="id-car">
<option *ngFor="let car of cars" [value]="car">{{car.make}} - {{car.model}}</option>
</datalist>
Run Code Online (Sandbox Code Playgroud)
这是一个可以玩这个的地方:https : //stackblitz.com/edit/angular-cwmwke
(欢迎任何人重新提出我的问题,我不确定如何说出来)
假设我创建了一个Angular组件,如下所示:
<app-my-test></app-my-test>
Run Code Online (Sandbox Code Playgroud)
如何通过在组件中键入选项来允许用户打开和关闭选项,如下所示:
<app-my-test booleanCheck></app-my-test>
Run Code Online (Sandbox Code Playgroud)
然后在我的.ts文件中,booleanCheck如果他们添加它,我想成为真实,如果他们没有添加它我会是假的.下面是一个可以玩的闪电战.我们的目标是让console.log登录true,如果booleanCheck加入,而false如果不添加它.
https://stackblitz.com/edit/angular-xr3p84?file=src%2Fapp%2Fapp.module.ts
我不希望这个答案请:
<app-my-test booleanCheck="true"></app-my-test>
<app-my-test [booleanCheck]="true"></app-my-test>
Run Code Online (Sandbox Code Playgroud) 在 JavaScript 中,` 在编写大字符串时非常有用。我的问题是它考虑了 JavaScript 中前面的空白量。因此,如果您的字符串在 JavaScript 中缩进,那么它在字符串中也会缩进。有什么办法可以摆脱这个吗?
因为在这样的示例中,我希望 html 标签与字符串的左侧齐平,但我不想使其与 JavaScript 的左侧齐平。检查 console.log 结果如何,以便更好地理解它。
MyFunction = function() {
console.log(`
<html>
<head>
</head>
<body>
</body>
</html>
`);
}
MyFunction();Run Code Online (Sandbox Code Playgroud)
控制台日志:
当我将示例添加到我的 swagger 文档中并在 swagger 编辑器上进行测试时,它永远不会显示在任何地方。有人能给我一个例子,说明多个例子实际上在任何地方显示吗?
它来自:https : //swagger.io/docs/specification/adding-examples/
下面是一个 yaml 示例,它examples在在线 swagger 编辑器上不显示任何内容:
openapi: 3.0.0
info:
title: Some API
version: 1.0.0
paths:
/logon:
get:
summary: Login user
tags:
- '/logon'
parameters:
- name: Client
in: query
required: true
examples:
zero:
value: '0'
summary: A sample limit value
max:
value: '50'
summary: A sample limit value
schema:
type: string
responses:
'200':
description: Success response
Run Code Online (Sandbox Code Playgroud) 我想知道如何"Content-Type": "application/json"为传入的每个nodejs表达请求设置标头。
我尝试了这两行,但是如果我自己不添加标题,我的呼叫仍然会失败:
app.use(function(req, res, next) {
req.header("Content-Type", "application/json");
res.header("Content-Type", "application/json");
next();
});
Run Code Online (Sandbox Code Playgroud)
我所有的请求都是json,所以我不希望前端(Anguler)每次向我发送此标头,只要我可以自己从服务器端进行设置。
我的父组件中有一个如下所示的对象,该对象被传递到我的子组件(应用程序自定义组件):
myObject = {
name: 'John'
}
...
<app-custom-component [inputObject]="myObject"></app-custom-component>
Run Code Online (Sandbox Code Playgroud)
在我的子组件(应用程序自定义组件)中,我这样做:
@Input() inputObject;
displayName = '';
ngOnInit() {
this.displayName = this.inputObject.name;
}
...
<label>{{displayName}}</label>
Run Code Online (Sandbox Code Playgroud)
但是当我更改myObject.name父组件中的 时,它不会更新子组件的displayName.
当父组件displayName发生变化时,如何进行更新?myObject.name
(这是在 SourceTree 中完成的)
我正在尝试创建一些分支(master/dev,, ) master/demo,master/live但这无法推送。例如,当我尝试推送时,master/demo它master/demo会给出以下错误:
git -c diff.mnemonicprefix=false -c core.quotepath=false push -v --tags --set-upstream origin master/demo:master/demo
fatal: HttpRequestException encountered.
An error occurred while sending the request.
POST git-receive-pack (206 bytes)
remote: error: cannot lock ref 'refs/heads/master/demo': 'refs/heads/master' exists; cannot create 'refs/heads/master/demo'
Pushing to https://x@bitbucket.org/x/x.git
To https://bitbucket.org/x/x.git
! [remote rejected] master/demo -> master/demo (failed to update ref)
error: failed to push some refs to 'https://x@bitbucket.org/x/x.git'
Completed with errors, see above.
Run Code Online (Sandbox Code Playgroud) 在我的Node.js项目中,我想await在继续执行代码之前先使用mongoose.save 函数。下面的示例不起作用,但是任何人都可以帮我解决一些问题。
app.post('/api/CreateUser', async (req, res) => {
const newUser = new User({
'email': req.body.email,
'name': req.body.name
});
console.log('before save');
await newUser.save((err, userDoc) => {
if (err) return res.status(400).send(err);
console.log('saved item');
});
console.log('after save');
});
Run Code Online (Sandbox Code Playgroud)
当前console.log的顺序是:
但我希望是:
如果希望凭据(cookie身份验证令牌)可通过调用传递,则需要添加{ withCredentials: true }httpclient调用。像这样:
import { HttpClient } from '@angular/common/http';
...
constructor(private httpclient: HttpClient) { }
this.httpclient.get(url, { withCredentials: true })
Run Code Online (Sandbox Code Playgroud)
我只想知道是否有一种方法可以{ withCredentials: true }对每个呼叫进行预设。我不想{ withCredentials: true }每次打电话时都添加。
这是一个相关的问题,但是我不确定这是否适用于HttpClient?
说我有这个对象:
myObj = {
level1: {
level2: {
name: 'Frank'
}
}
};
Run Code Online (Sandbox Code Playgroud)
如何使用hasOwnProperty()检查对象的多个深度.像这样的东西有效:
if (myObj.hasOwnProperty('level1') {
if (myObj.hasOwnProperty('level2') {
if (myObj.hasOwnProperty('name') {
console.log(myObj.level1.level2.name)
}
}
}
Run Code Online (Sandbox Code Playgroud)
我希望有类似的东西:
myObj.hasOwnProperty(['level1', 'level2', 'name']);
myObj.hasOwnProperty('level1.level2.name);
Run Code Online (Sandbox Code Playgroud)
我的目标是,console.log(myObj.level1.level2.name)如果不是所有的属性都存在,那么你可以通过提供替代hasOwnProperty也来回答这个问题.
为什么我会收到此错误?
set session my.vars.id = SELECT "Name" FROM "Client" WHERE "ID" = 1;
SELECT * FROM "Client" WHERE "Name" = current_setting('my.vars.id');
...
ERROR: syntax error at or near "SELECT"
LINE 1: set session my.vars.id = SELECT "Name" FROM "Client" WHERE "...
^
Run Code Online (Sandbox Code Playgroud) angular ×4
node.js ×3
html ×2
http ×2
javascript ×2
async-await ×1
asynchronous ×1
bitbucket ×1
datalist ×1
express ×1
git ×1
header ×1
mongoose ×1
postgresql ×1
promise ×1
string ×1
subscribe ×1
swagger ×1
yaml ×1