我正在尝试将Angular 5.2应用程序更新为Angular 6.我成功地遵循了Angular更新指南中的说明(包括更新angular-cli
到v6),现在我正在尝试通过
ng serve --env=local
Run Code Online (Sandbox Code Playgroud)
但这给了我错误:
未知选项:' - env'
我使用多个环境(dev/local/prod
),这就是它在Angular 5.2中的工作方式.如何在Angular 6中设置环境?
使用 MikroORM 并收到此错误:
ValidationError: Using global EntityManager instance methods for context specific actions is disallowed.
If you need to work with the global instance's identity map, use `allowGlobalContext` configuration option or `fork()` instead
Run Code Online (Sandbox Code Playgroud)
其对应的代码如下:
import { MikroORM } from "@mikro-orm/core";
import { __prod__ } from "./constants";
import { Post } from "./entities/Post";
import mikroConfig from "./mikro-orm.config";
const main = async () => {
const orm = await MikroORM.init(mikroConfig);
const post = orm.em.create(Post, {
title: "my first post",
});
await orm.em.persistAndFlush(post); …
Run Code Online (Sandbox Code Playgroud) 在角度材质2中,如何在切换组中设置默认选定按钮.
一旦我点击一个,它就会切换,但默认情况下都会以某种方式选择.我尝试如下,但不起作用.
<md-button-toggle-group #group="mdButtonToggleGroup">
<md-button-toggle (click)="firstTapped()" selected>
<span>one</span>
</md-button-toggle>
<md-button-toggle (click)="secondTapped()">
<span>second</span>
</md-button-toggle>
</md-button-toggle-group>
Run Code Online (Sandbox Code Playgroud) 我有两个系列
帖子:
{
"_Id": "1",
"_PostTypeId": "1",
"_AcceptedAnswerId": "192",
"_CreationDate": "2012-02-08T20:02:48.790",
"_Score": "10",
...
"_OwnerUserId": "6",
...
},
...
Run Code Online (Sandbox Code Playgroud)
和用户:
{
"_Id": "1",
"_Reputation": "101",
"_CreationDate": "2012-02-08T19:45:13.447",
"_DisplayName": "Geoff Dalgas",
...
"_AccountId": "2"
},
...
Run Code Online (Sandbox Code Playgroud)
我想找到写5到15个帖子的用户.这是我的查询的样子:
db.posts.aggregate([
{
$lookup: {
from: "users",
localField: "_OwnerUserId",
foreignField: "_AccountId",
as: "X"
}
},
{
$group: {
_id: "$X._AccountId",
posts: { $sum: 1 }
}
},
{
$match : {posts: {$gte: 5, $lte: 15}}
},
{
$sort: {posts: -1 }
},
{
$project : …
Run Code Online (Sandbox Code Playgroud) 我正在忙于一个我正在使用angular-flex-layout的项目.据我所知,如果将fxLayoutWrap属性应用于容器,则flex容器应该换行到下一行.由于某种原因,我有一个非常小的x溢出.它曾经更大,然后我删除了我在两个fxLayout行容器上的一些fxLayoutGaps,这使它变得更好.当我将fxLayoutWrap属性应用于父(仪表板组件的第一行)行容器时,我不知道这可能是什么原因.知道我做错了什么吗?
滚动到右侧后页面的图片
滚动到右边之前的图片:
我的代码:
我的主页组件的HTML:
<mat-sidenav-container position="start" class="custom-sidenav-container">
<mat-sidenav #sidenav mode="side" opened="true">
Navigation
<ul class="sn-list">
<li>
<mat-icon class="sn-item">
<i class="material-icons">dashboard</i>
</mat-icon>
<a class="sn-item" href="#">Dashboard</a>
</li>
<li>
<mat-icon class="sn-item">
<i class="material-icons">archive</i>
</mat-icon>
<span class="sn-item" [matMenuTriggerFor]="stockSystemMenu">Stok System</span>
<mat-menu [overlapTrigger]="false" #stockSystemMenu="matMenu">
<button mat-menu-item>
<mat-icon class="sn-item">
<i class="material-icons">chevron_right</i>
</mat-icon>
<span class="sn-item">Service 1</span>
</button>
<button mat-menu-item>
<mat-icon class="sn-item">
<i class="material-icons">chevron_right</i>
</mat-icon>
<span class="sn-item">Service 2</span>
</button>
<button mat-menu-item>
<mat-icon class="sn-item">
<i class="material-icons">chevron_right</i>
</mat-icon>
<span class="sn-item">Service 3</span>
</button>
</mat-menu>
</li>
<li>
<mat-icon class="sn-item">
<i class="material-icons">shopping_cart</i> …
Run Code Online (Sandbox Code Playgroud) 试图使MikroORM 中的populate
参数对带有字符串路径的变体严格。我设法实现(更像是调整我在 TS discord 上找到的那个)根据我的需要工作的类型。当与单个参数一起使用时它可以正常工作,但是当与数组一起使用时,如果数组项之一有效,它将无法正确验证。AuthPath
所以问题是,我怎样才能让它与数组一起工作?甚至有可能吗?我试图使用元组类型来解决这个问题,但未能使其正常工作。我有点理解问题是共享泛型类型P
- 我计划在返回类型中利用它,所以我需要一些东西来暴露从 params 到返回类型的签名中的实际(推断)类型。
完整的操场在这里。
下面是问题的演示:
declare const user: User;
declare function get1<O, P extends string>(obj: O, path: AutoPath<O, P>): void;
declare function get2<O, P extends string>(obj: O, path: AutoPath<O, P>[]): void;
// works fine with single item
get1(user, "friend.books.title")
get1(user, "friend.books.ref1.age")
get1(user, "friend.friend.name")
// @ts-expect-error
get1(user, "friend.friend.www")
// @ts-expect-error
get1(user, "friend.books.www")
// @ts-expect-error
get1(user, "friend.books.ref1.www")
// works fine with array when there is just one …
Run Code Online (Sandbox Code Playgroud) 我注意到一台配有1920x1080屏幕的小型笔记本电脑,Windows 10会自动调整缩放比例.我看到它高达150%.有没有办法可以发现这个?我的媒体查询没有启动,因为它们是在px中设置的.
在这里,我有两种服务方法。我对此并不陌生,所以不确定是否可以使用订阅方法,但是我知道如果没有它,我将无法构建我的项目。如果我评论这两个功能,则先提供服务,然后取消评论,然后让其刷新更改,即可正常工作。但是我不能建立项目。如何更改代码,这样就不会出现那些错误并成功构建项目?
public delete(patient: Patient): Observable<Patient> {
return this.http.delete<Patient>(`${this.deleteOneUrl}/${patient.id}`).subscribe();
}
public addPatient(patient: Patient): Observable<Patient> {
return this.http.post<Patient>(this.addOneUrl, patient).subscribe();
}
Run Code Online (Sandbox Code Playgroud)
src / app / patient.service.ts(30,3)中的错误:错误TS2322:类型“ Subscription”不能分配给类型“ Observable”。“预订”类型中缺少属性“ _isScalar”。src / app / Patient.service.ts(38,5):错误TS2322:类型“ Subscription”不能分配给类型“ Observable”。
在这个材料2片段中,我们如何确保具有该draft
值的按钮恰好是默认值?文档提及selected
和checked
指令,但它们似乎不起作用.
<mat-button-toggle-group #group="matButtonToggleGroup" matInput name="status" [(ngModel)]="status" #field_status="ngModel">
<mat-button-toggle checked? selected? default? value="draft">
DRAFT <--how do we set this value to be the default selected/checked one? -->
</mat-button-toggle>
<mat-button-toggle value="publish">
PUBLISH
</mat-button-toggle>
</mat-button-toggle-group>
Run Code Online (Sandbox Code Playgroud) 在for循环中我可以使用break
或continue
.例如:
for(var i=0;i<5;i++){
if(i=3){
continue; //I know this is absurd to use continue here but it's only for example
}
}
Run Code Online (Sandbox Code Playgroud)
但是,如果我想continue
在for循环中的函数内使用该怎么办呢.
例如:
for(var i=0;i<5;i++){
theFunction(i);
}
function theFunction(var x){
if(x==3){
continue;
}
}
Run Code Online (Sandbox Code Playgroud)
我知道这会引发错误.但是,有没有办法让它工作或做类似的事情?
有什么方法可以在不调用其构造函数的情况下实例化新的类实例吗?
像这样:
class Test {
constructor(foo) {
this.foo = 'test';
}
}
const a = new Test('bar'); // call constructor
const b = Test.create(); // do not call constructor
console.log(a.foo, a instanceof Test); // bar, true
console.log(b.foo, b instanceof Test); // undefined, true
Run Code Online (Sandbox Code Playgroud)
我正在尝试开发TS mongo ORM,并希望使用实体的构造函数来创建新对象,但是当实例化已持久化对象(已经存储在DB中的那些对象)的实体时,不想调用它们。
我知道该学说(PHP ORM)使用这种方法,但是afaik他们使用代理类来实现它。有没有简单的方法可以在打字稿中(或通常在ES6 / ES7中)实现这一点?
我已经发现了这个问题ES6:不带new关键字的类构造函数,它要求相反,并看到一个提及Proxy
对象的答案。听起来这是一种可行的方法,但是从文档中我不确定它是否可以实现。
我目前正在学习Angular,并且正在关注一些教程,我创建了一个简单的注册组件:
import { Component, OnInit } from '@angular/core';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
@Component({
selector: 'app-register',
templateUrl: './register.component.html',
styleUrls: ['./register.component.css']
})
export class RegisterComponent implements OnInit {
form: FormGroup;
createForm() {
this.form = this.formBuilder.group({
email: '',
username: '',
password: '',
confirm: ''
})
}
onRegisterSubmit() {
console.log('this.form');
}
constructor(private formBuilder: FormBuilder) {
this.createForm();
}
ngOnInit() {
}
}
Run Code Online (Sandbox Code Playgroud)
并在html中定义了以下格式:
<h1 class="page-header">Registration Page</h1>
<form [formGroup]="form" ng-submit="onRegisterSubmit()">
<div class="form-group">
<label for="username">Username</label>
<div>
<input type="text" name="username" class="form-control" autocomplete="off" placeholder="*Username" formControlName="username" …
Run Code Online (Sandbox Code Playgroud) angular ×6
typescript ×4
javascript ×3
css ×2
node.js ×2
angular-cli ×1
angular6 ×1
ecmascript-6 ×1
es6-class ×1
flexbox ×1
graphql ×1
html5 ×1
mean-stack ×1
mikro-orm ×1
mongodb ×1