如此处所述, TypeScript引入了一个foreach循环:
var someArray = [9, 2, 5];
for (var item of someArray) {
console.log(item); // 9,2,5
}
Run Code Online (Sandbox Code Playgroud)
但是没有任何索引/密钥吗?我希望有类似的东西:
for (var item, key of someArray) { ... }
Run Code Online (Sandbox Code Playgroud) 我们不能在模板中使用按位运算符,但为什么在TypeScript代码中tslint不允许它们?
"no-bitwise": true,
Run Code Online (Sandbox Code Playgroud) 我有多个应用程序想要共享相同的 eslint 配置:
- project_root/
- app1/
- node_modules/
- eslint.rc
- app2/
- node_modules/
- eslint.rc
- app3/
- node_modules/
- eslint.rc
- eslint.rc
Run Code Online (Sandbox Code Playgroud)
每个应用程序都有相同的配置:
module.exports = {
extends: [
'../.eslintrc',
],
};
Run Code Online (Sandbox Code Playgroud)
在根目录中,我想配置所有内容:
module.exports = {
parser: '@typescript-eslint/parser',
parserOptions: {
project: 'tsconfig.json',
sourceType: 'module',
},
plugins: ['@typescript-eslint/eslint-plugin'],
extends: [
'plugin:@typescript-eslint/eslint-recommended',
'plugin:@typescript-eslint/recommended',
'prettier',
'prettier/@typescript-eslint',
],
root: true,
env: {
node: true,
jest: true,
},
rules: {},
};
Run Code Online (Sandbox Code Playgroud)
但是现在每个应用程序都会抛出无法找到节点模块的错误:
无法加载在“.eslintrc.js»../.eslintrc”中声明的解析器“@typescript-eslint/parser”:找不到模块“@typescript-eslint/parser”。
我在根目录中没有任何 node_modules,我想避免它。
我有三个包:
A
, 依赖于取决于C
B
, 依赖于取决于C
C
使用时lerna run build
,在和C
之前构建(好!)A
B
但是,当我开始观看任务时lerna run watch
,C
永远不会完成,因此A
不会B
被观看。
使用lerna run watch --parallel
starts A
、B
andC
同时butA
和B
都抛出错误,因为它们无法从中找到dist文件夹C
(C
在重建之前刚刚删除)。
有没有什么方法可以启动监视任务,但仍然像正常运行一样保持依赖关系的顺序?或者至少推迟一些其他人?
我尝试使用 registerAsync 导入模块并使用模块中的提供程序配置它,但它会抛出错误,无法找到该提供程序。我缺少什么?
我的代码:
import { CacheModule, Module } from '@nestjs/common';
@Module({
imports: [
CacheModule.registerAsync({
useFactory: async (options) => ({
ttl: options.ttl,
}),
inject: ['MY_OPTIONS'],
}),
],
providers: [
{
provide: 'MY_OPTIONS',
useValue: {
ttl: 60,
},
},
],
})
export class AppModule {
}
Run Code Online (Sandbox Code Playgroud)
错误:
错误:Nest 无法解析 CACHE_MODULE_OPTIONS 的依赖关系(?)。请确保索引 [0] 处的参数 MY_OPTIONS 在 CacheModule 上下文中可用。
上面的例子是我的代码的简化。但主要问题保持不变:我在 AppModule 中有一个提供程序,并且我在 CacheModule.registerAsync() 函数中需要它。
如果有人想尝试解决这个问题,我做了一个非常简单的存储库:https ://github.com/MickL/nestjs-inject-existing-provider
我有嵌套组件:
我使用 Router 的Resolve解析主菜单和页面内容:
const routes: Routes = [
{
path: '',
component: PageWrapperComponent,
resolve: {
mainMenu: MainMenuResoler,
},
children: [
{
path: '',
component: ContentComponent,
resolve: {
content: ContentResolver,
}
}
]
];
Run Code Online (Sandbox Code Playgroud)
我想在 MainMenuResoler 完成后立即显示主菜单(PageWrapperComponent)。ContentResolver 完成后,然后就是内容(ContentComponent)。但如何呢?
我预料到路由器会出现这种行为。相反,Angular 会等待两个解析器完成,然后同时显示 PageWrapperComponent 和 ContentComponent。
我有一个myFile
在控制台中看起来像这样的File对象:
File {
name: "myimage.jpg",
lastModified: 1465476925001,
lastModifiedDate: Thu Jun 09 2016 14:55:25 GMT+0200 (CEST),
size: 33002
type: "image/jpeg"
}
Run Code Online (Sandbox Code Playgroud)
但是当我用它创建一个图像时
var image = new Image();
image.src = URL.createObjectURL(myFile);
Run Code Online (Sandbox Code Playgroud)
我明白了:
<img src="blob:http://myurl.com/6b2b83d8-ac36-40c1-8ab1-c4f07b019ba5">
Run Code Online (Sandbox Code Playgroud)
当我尝试右键单击保存文件时,文件名为空或"6b2b83d8-ac36-40c1-8ab1-c4f07b019ba5"而不是"myimage.jpg".文件对象中的文件名已消失.有没有办法设置图像文件名?
我尝试为我的TypeScript/Angular 2 App制作日志服务.不幸的是,如果我调用console.log,行号是错误的.即使我试着return console.log()
.
这是我的代码:
LoggerService.ts
export class LoggerService {
log(message) {
// Server-side logging
// [...]
if (clientSideLogging) return console.log(message);
}
}
Run Code Online (Sandbox Code Playgroud)
SomewhereElse.ts
this.logger.log('hello world');
Run Code Online (Sandbox Code Playgroud)
- >显示LoggerService.ts而不是source的行号
像容器一样<app-root></app-root>
可以破坏css布局,尤其是在使用flexbox时.
是否可以使用隐形组件容器?我selector: '[app-root]'
已尝试使用以下标记,但它们都创建了一个dom元素:
<template>, <ng-template>, <ng-template>, <ng-container>
Run Code Online (Sandbox Code Playgroud)
如果确实需要这个容器,那么如果Angular只呈现HTML注释会很棒.
我正在导入一个第三方模块,该模块导入另一个模块:
import fetch from "cross-fetch";
我想告诉 Webpack 忽略/删除此导入,因为该变量fetch
已存在于全局命名空间中。那可能吗?
angular ×5
javascript ×4
typescript ×4
console.log ×1
eslint ×1
fileapi ×1
filereader ×1
for-loop ×1
foreach ×1
image ×1
lerna ×1
nestjs ×1
node-modules ×1
node.js ×1
prettier ×1
tslint ×1
webpack ×1