我有角形。
当我打开应用程序时,控制台会记录in fooValidation
四次,而我什么也不做。
in fooValidation
in fooValidation
in fooValidation
in fooValidation
Run Code Online (Sandbox Code Playgroud)
为什么?这是设计使然吗?如何使其仅在表单提交后或焦点位于指定字段时执行?
in fooValidation
in fooValidation
in fooValidation
in fooValidation
Run Code Online (Sandbox Code Playgroud)
在我的第一个项目,我们使用express
和mysql
图书馆没有任何ORM,我们打开连接时,控制器启动和关闭在这方面finaly
块。我一直认为这个方法是对的。
但是现在我开始用 NestJS + TypeORM 做一个应用程序,当我的服务器启动时 - 连接已准备好打开!我想知道是否可以,开始谷歌但更困惑。
例如人们说
“你必须只在需要的时候打开连接,使用后立即关闭它,因为你不应该保持 1 个打开的连接,其他用户可能需要它”。
他们还说:
“你必须使用连接池。连接池打开 1+ 个连接并保持它们打开。当你的应用程序中的某个线程需要它时,它不会浪费时间打开”..
什么?这两个句子互相排斥。
所以,
问题1:谁是对的?
问题2:
如果 TypeORM 使用“连接池”,那么它的优势是什么,如果我的控制器将始终使用“默认连接”?
@Injectable()
export class UsersService {
constructor(
@InjectRepository(User)
private usersRepository: Repository<User>,
) {}
findAll(): Promise<User[]> {
return this.usersRepository.find();
}
}
Run Code Online (Sandbox Code Playgroud)
如果 1kk 用户同时请求此控制器 - TypeORM 不会在用户池中创建额外连接以防止一个连接过载。那么,TypeORM 连接池有什么意义呢?
我创建 POST 端点来创建一个新实体。我还使用字段 userId (将此实体连接到指定用户)和 DTO 创建了 mongoose 模式,我在 POST 方法中使用了 DTO。
@UseGuards(JwtAuthGuard)
@Post("/")
createAction(@Request() req, @Body() createActionDto: CreateActionDto) {
return this.actionService.createAction(req?.user?.userId, createActionDto);
}
Run Code Online (Sandbox Code Playgroud)
数据传输对象:
import { IsString, IsNumber, IsUrl } from 'class-validator';
export class CreateActionDto {
userId: string;
@IsString()
name: string;
@IsNumber()
timeStart: number;
}
Run Code Online (Sandbox Code Playgroud)
架构:
import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
import { Document } from 'mongoose';
@Schema()
export class Action extends Document {
@Prop()
userId: string;
@Prop()
name: string;
@Prop()
timeStart: number;
}
export const …
Run Code Online (Sandbox Code Playgroud) 我遇到了以下问题,该问题已由{static: false}
中的属性修复@ViewChild
。\n此 stackoverflow Q/A 帮助解决了How should I use the new static option for @ViewChild in Angular 8? 。
我想更好地理解这个场景以及如何static
改变结果,以及变化检测如何影响这个场景。我已经阅读了角度文档中有关更改检测的一些内容,并发现极其缺乏。
我想出了一个 stackblitz 来说明一些我不明白的事情。Stackblitz 角度示例
\n单击toggle
按钮两次时,我在命令行上收到以下内容:
> undefined undefined\n> undefined undefined\n> undefined ElementRef\xc2\xa0{nativeElement: div}\n> undefined ElementRef\xc2\xa0{nativeElement: div}\n\n
Run Code Online (Sandbox Code Playgroud)\n不过我期望:
\n> undefined undefined\n> undefined ElementRef\xc2\xa0{nativeElement: div}\n> ElementRef\xc2\xa0{nativeElement: div} ElementRef\xc2\xa0{nativeElement: div}\n> ElementRef\xc2\xa0{nativeElement: div} ElementRef\xc2\xa0{nativeElement: div}\n\n
Run Code Online (Sandbox Code Playgroud)\n这是代码的逻辑——(请参阅 stackblitz 中的完整代码)
\n> undefined undefined\n> undefined undefined\n> undefined ElementRef\xc2\xa0{nativeElement: div}\n> undefined …
Run Code Online (Sandbox Code Playgroud) 我已经使用 sendInBlue 创建了一个帐户,并将 nodemailer 和 nodemailer-sendinblue-transport 导入到我的项目中,我试图在其中发送一封简单的确认电子邮件。以下代码是我尝试设置的方式:
const transporter = nodemailer.createTransport(
sendinblueTransport({
auth: {
apiKey: 'key'
}
})
);
Run Code Online (Sandbox Code Playgroud)
以下代码是我的注册方法中负责发送确认电子邮件的部分:
return transporter.sendMail({
to: email,
from: 'person@gmail.com',
subject: 'Signup succeeded!',
html: '<h1>You successfully signed up!</h1>'
});
Run Code Online (Sandbox Code Playgroud)
当我运行我的程序时,注册过程成功,但抛出以下错误而不是发送电子邮件:
错误:在数据库中找不到密钥(失败,401)
我读到他们的 v2 API 可能会贬值,但他们的客户支持成员说他们仍然为 nodemailer 提供支持,可能是什么问题?我也尝试过 sendGrid 和 Mandrill,但前者有一个非常有问题的网站,不允许我登录,后者需要一个活动域来发送电子邮件。
谢谢
有问题的代码:
<%= if flash[:notice] %>
<div class="notification is-primary global-notification">
<p class="notice"><%= notice %></p>
</div>
<% end %>
<%= if flash[:alert] %>
<div class="notification is-danger global-notification">
<p class="alert"><%= alert %></p>
</div>
<% end %>
Run Code Online (Sandbox Code Playgroud)
已将语法更改为:if (flash[:notice])
。但是,还是放下这个。任何的想法?
我使用以下方法使元素全屏显示:
if (element.requestFullscreen) {
element.requestFullscreen();
} else if (element.msRequestFullscreen) {
element.msRequestFullscreen();
} else if (element.mozRequestFullScreen) {
element.mozRequestFullScreen();
} else if (element.webkitRequestFullscreen) {
element.webkitRequestFullscreen();
} else {
return;
}
Run Code Online (Sandbox Code Playgroud)
它工作得很好,但我想在全屏模式下显示另一个元素。
另一个元素有position: fixed
和z-index: 999999999
,但在全屏模式下不可见。
有人可以帮我吗?
下面是示例的链接
https://stackblitz.com/edit/web-platform-z1phjd?file=index.html
所以我想当红色元素全屏大小时显示蓝色元素。
export class AppComponent implements OnInit, OnChanges {
@Input()
value: number;
constructor(
private cdr: ChangeDetectorRef
) {}
ngOnInit() {
of(1).subscribe(v => {
this.value = v;
console.log(1);
this.cdr.detectChanges();
of(2).subscribe(() => {
console.log(2);
});
})
}
ngOnChanges(c: SimpleChanges) {
console.log(3);
}
}
Run Code Online (Sandbox Code Playgroud)
我希望 console.log 的序列应该是1, 3, 2
但它只打印1, 2
.
我知道ngOnChanges
只有在input
模板绑定发生更改时才会触发。
所以我this.cdr.detectChanges()
马上打电话,console.log(1)
但没有奏效。
这里有什么问题?
我在这里制作了 stackblitz 示例 - https://stackblitz.com/edit/angular-ivy-ugdba1
额外问题
如果无法触发ngOnChanges
组件内部,将触发哪些生命周期钩子this.cdr.detectChanges()
?
angular ×3
nestjs ×2
node.js ×2
database ×1
erb ×1
html ×1
javascript ×1
ngonchanges ×1
nodemailer ×1
ruby ×1
typeorm ×1
viewchild ×1