我是 Angular 新手,我正在尝试让我的路由器正常工作。/基本上,我有一个带有路由器链接的主页/courses,该链接运行良好,但是当我重新加载/courses(或输入地址)时,它会将我带回到主页,如果我再次单击路由器链接,它将带我到/courses/courses哪个是相同,/courses但这似乎是错误的。另外,如果我输入,/courses/则会收到 404 错误。
如果有人对如何解决这个问题有任何建议,我将非常感激!
// app-routing.module.ts is:
import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import {CoursesComponent} from './courses/courses.component';
import {ReviewsComponent} from './reviews/reviews.component';
import { CommonModule } from '@angular/common';
const routes: Routes = [
{
path: 'courses',
component: CoursesComponent
},
{
path: 'courses/:id',
component: ReviewsComponent
}
];
@NgModule({
imports: [RouterModule.forRoot(routes),
CommonModule],
exports: [RouterModule]
})
export class AppRoutingModule { }
Run Code Online (Sandbox Code Playgroud)
<!-- app.component.html …Run Code Online (Sandbox Code Playgroud) Im using BehaviourSubject from RxJS:
private rights = new BehaviorSubject<Array<string>>([]);
updateRights(rights: Array<string>) {
this.rights.next(rights);
}
getRights(): Observable<any> {
return this.rights.asObservable();
}
Run Code Online (Sandbox Code Playgroud)
I'm updating the rights in the root component and im subscribing to it in another component like:
this.configService.getRights().subscribe(res => {
console.log(res);
})
Run Code Online (Sandbox Code Playgroud)
This subscription is firing twice. Once when the data is empty and then again when the data is received.
I want the subscription to fire only once and get only the latest data. What should be done?
我想创建可以在传入数据到达数据库之前对其进行转换的功能。假设我们要确保在创建新用户时, firstName 和 lastName 属性值始终以大写字母开头。或者另一个很好的例子是防止登录问题并始终以小写字母存储电子邮件地址。
我查看了 NestJS 的管道文档,但它太通用了。我希望能够指定哪些字段需要转换,并且我不想为每个需要转换的属性或端点创建管道。
我也尝试过 @Transform 装饰器形成“class-transformer”包,但这似乎不起作用。
export class UserRoleCreateDto {
@IsDefined()
@IsString()
@IsNotEmpty()
@Transform((name) => name.toUpperCase())
readonly name;
}
Run Code Online (Sandbox Code Playgroud)
预期的结果应该是大写字母的名称,但事实并非如此。
任何关于如何在 NestJS / TypeORM 命中数据库之前实现正确输入转换的想法或示例?
谢谢你的时间!
我有以下三个模型:Product,Warehouse和Inventory
# app/models/product.rb
class Product < ApplicationRecord
has_many :inventories
has_many :warehouses, through: :inventories
end
# app/models/warehouse.rb
class Warehouse < ApplicationRecord
has_many :inventories
has_many :products, through: :inventories
end
# app/models/inventory.rb
class Inventory < ApplicationRecord
belongs_to :product
belongs_to :warehouse
end
Run Code Online (Sandbox Code Playgroud)
我有这个库存工厂:
FactoryBot.define do
factory :inventory do
product { nil }
warehouse { nil }
item_count { 1 }
low_item_threshold { 1 }
end
end
Run Code Online (Sandbox Code Playgroud)
我如何将这个工厂用于库存,或者我的其他工厂需要进行哪些更改,以便我可以拥有这样的规范?
RSpec.describe Inventory, type: :model do
it "has a valid factory" do
expect(FactoryBot.build(:inventory)).to …Run Code Online (Sandbox Code Playgroud) 如何设置AUTO_INCREMENT的@PrimaryColumn()?
我知道这样@PrimaryGeneratedColumn()做,但我想从double类型中获得 ID 。
是否有可能有@PrimaryGeneratedColumn()同double类型?如果没有我可以设置AUTO_INCREMENT为@PrimaryColumn()?
我有一个从 http 加载数据的图表组件:
export class BarChartComponent implements OnInit {
dataObservable: Observable<any>;
constructor(private httpClient: HttpClient){
this.dataObservable = this.httpClient.get<any[]>(response.dataEndpoint);
}
ngOnInit() {
this.dataObservable.subscribe((data: any) => {
//draw chart
})
}
search() {
this.dataObservable = this.httpClient.get<any[]>(`${this.dataEndpoint}/category=123`);
this.dataObservable.subscribe((data: any) => {
//draw chart
})
}
}
Run Code Online (Sandbox Code Playgroud)
我设置了dataObservable构造函数并订阅了ngOnInit()函数。但我使用查询字符串更改了 URL,并再次收到请求。于是我又订阅了new。但我已经订阅了ngOnInit()。
我可以重新加载 observable 而无需再次订阅吗?
fn main() {
let mut str = "string".to_string();
// How do I push String to String?
str.push_str(format!("{}", "new_string"));
}
Run Code Online (Sandbox Code Playgroud)
那么,如何将格式化的字符串推入呢str?我不想串联。连接与推送有点相同,但我想知道如何推送String。
我是ctags的忠实粉丝,但有时很难使用它.
如果我有一些具有相同名称的函数声明 - "ctrl +]"会引发您第一次出现 - 这并不总是我需要的.
如何查看匹配标签的完整列表,以便我可以选择打开哪一个?
我正在尝试在源代码中完成以下内容:
<div id="box<%=id%>"></div>
Run Code Online (Sandbox Code Playgroud)
没有逃避哈姆的任何迹象.
%div{ :id => "box_<%=id%>" }
Run Code Online (Sandbox Code Playgroud)
产生
<div id='box_<%=id%>'></div>
Run Code Online (Sandbox Code Playgroud)
现在,我可以使用Haml执行此操作的唯一方法是在:plain不使用任何View Helpers的情况下使用过滤器和硬编码HTML.我该如何解决这个问题?
我需要这个,因为我因为第三方语法约定而被迫遵循这个约定:JavaScript Micro-Templating
参考:
我是 Emacs 新手,并完成了 Emacs 和基本 org-mode 教程。\n现在我想安装 org-drill。以下是我在 Emacs 上安装 org-drill 的失败尝试。
\n\n从http://orgmode.org/worg/org-contrib/org-drill.html
\n\n\n\n\n安装
\n\n最简单的方法是自定义变量“org-modules”(Mxcustomize-variables RET org-modules)并确保勾选“drill”。
\n
我打开 spanish.org 文件并在 Emacs 中输入“Meta-xcustomize-variables”,回显区域显示:
\n\nM-x customize-variables [No match]\nRun Code Online (Sandbox Code Playgroud)\n\n所以我尝试“Meta-x custom-variable”单数:
\n\nM-x customize-variable <RET> org-modules\nRun Code Online (Sandbox Code Playgroud)\n\n自定义菜单对组织模块开放。\n因此“Mxcustomize-variables”末尾的“\'s\”是说明中的拼写错误,或者是我做错了。
\n\n在“自定义”菜单中,我选中“钻取”并单击“应用并保存”按钮。
\n\n退出并重新启动 Emacs。
\n\n打开 spanish.org 文件。
\n\n在 Emacs 中输入“Mx org-drill”,回显区域显示:
\n\nM-x org-drill-table-\nRun Code Online (Sandbox Code Playgroud)\n\n为什么没有“org-drill”?\n我输入:
\n\nM-x customize-variable <RET> org-modules\nRun Code Online (Sandbox Code Playgroud)\n\n“钻”仍然被选中。
\n\n然后我尝试了手动安装说明:
\n\n\n对于手动安装,请将以下内容放入 .emacs 中。您还需要确保 Org\ 的“contrib/lisp”目录位于 emacs …