我喜欢resolvers 的想法.
您可以这样说:
- 对于给定的路径,您希望首先加载一些数据
- 您可以拥有一个没有可观察的非常简单的组件(从中检索数据this.route.snapshot.data)
解析器很有意义.
但是:
- 在收到实际响应之前,您不会更改URL并显示您请求的组件.因此,您不能(简单地)通过呈现组件并尽可能多地显示用户来显示用户正在发生的事情(就像建议使用PWA的shell应用程序一样).这意味着当连接不良时,您的用户可能只需要等待很长时间没有视觉指示正在发生的事情
- 如果您在使用参数的路线上使用解析器,让我们以其为例users/1,它将正常工作第一次.但是如果你去users/2,除非你开始使用另一个observable,否则什么都不会发生:this.route.data.subscribe()
所以感觉解析器可能有助于检索一些数据但在实践中我不会使用它们以防万一网络速度慢,特别是对于带有参数的路由.
我在这里错过了什么吗?有没有办法将它们与那些真正的约束一起使用?
我希望能够使用Visual Studio Code调试Angular2应用程序.
这是我的环境:
使用angular-cli创建一个新项目:
ng new test-VSC-debug
cd test-VSC-debug
Run Code Online (Sandbox Code Playgroud)
然后我打开VSC并加载项目: File/open folder
我点击debug的标志,我configure launch.json的选择chrome.它生成以下文件:
{
"version": "0.2.0",
"configurations": [
{
"name": "Launch Chrome against localhost, with sourcemaps",
"type": "chrome",
"request": "launch",
"url": "http://localhost:8080",
"sourceMaps": true,
"webRoot": "${workspaceRoot}"
},
{
"name": "Attach to Chrome, with sourcemaps",
"type": "chrome",
"request": "attach",
"port": 9222,
"sourceMaps": true,
"webRoot": "${workspaceRoot}"
}
]
}
Run Code Online (Sandbox Code Playgroud)
然后我通过运行启动angular2项目:
ng serve …Run Code Online (Sandbox Code Playgroud) google-chrome-devtools visual-studio-code angular-cli angular
我最近更新了CodeIgniter 3,遵循本指南: CI3:从2.2.1升级3.0.
我在application/config/config.php文件中设置了这个配置:
$config['sess_driver'] = 'files';
$config['sess_cookie_name'] = 'ci_session_my_site';
$config['sess_expiration'] = 604800; // 1 week
$config['sess_save_path'] = NULL;
$config['sess_match_ip'] = FALSE;
$config['sess_time_to_update'] = 300;
Run Code Online (Sandbox Code Playgroud)
这里有什么问题吗?我的会话在几个小时后就被销毁了......
我正在构建Chrome应用.该应用程序使用TypeScript(Angular2)编写.
我想推送通知.这是代码:
import {Injectable} from 'angular2/core';
@Injectable()
export class NotificationService {
constructor() {
if(Notification.permission !== 'granted') {
Notification.requestPermission();
}
}
}
Run Code Online (Sandbox Code Playgroud)
当gulp构建应用程序时,它说:
src/scripts/stream/notification.service.ts(6) Cannot find name 'Notification'.
Run Code Online (Sandbox Code Playgroud)
我试着把我的课包在里面:
/* tslint:disable */
... the code
/* tslint:enable */
Run Code Online (Sandbox Code Playgroud)
但它没有改变任何东西.
有没有办法用tslint.json文件告诉Typescript这是一个全局变量?
使用jshint会是这样的:
"globals": {
"Notification": false
}
Run Code Online (Sandbox Code Playgroud) 我有一个git repo,基本上是Bootstrap的一个分支.
它已被修改,我可以推动其他回购比官方回购.仍然可以从Bootstrap中获取(以获取更新).
我的问题是,当我进入bower install http://my_custom_url.git凉亭下载官方的Bootstrap回购而不是我的.
我无法弄清楚为什么,不幸的是我无法分享我的回购的真实网址(它被我的公司锁定).
任何帮助将非常感谢,谢谢!
我正在尝试找到一种使用 DTO(使用辉煌class-validator和class-transformer库)验证主体的好方法。它工作得非常好,即使对于嵌套结构也是如此,但在我的情况下,我希望根据某些条件拥有 body 属性。
可能有助于理解的示例:
让我们想象一下我的身体应该总是有selectedCategory。根据该字段,内容可能来自类别 1,其中包含prop1OR 来自类别 2,其中包含prop2.
我不想让他们两个都为空,我真的想要么已经prop1定义要么prop2基于selectedCategory.
我认为我可以使用管道,但是如何指定要使用的正确 DTO?
我已经构建了一个“基”类,其中包含所有公共属性和一些继承自它的其他类。
我可以根据属性手动实例化管道selectedCategory,这是理想的,但我不知道将什么作为管道的第二个参数(元数据)传递。
谢谢你的帮助。
语境:
我们的网络应用程序可以同时显示不同的帮助面板。
当面板需要给定的 ID(例如help-id-1)时,我们会访问一个 API,传递该 ID,然后我们会得到所需的帮助。
现在,由于某些原因,我们可能会显示同一帮助面板两次或多次。但是,当然,如果提取时没有错误或当前正在提取,我们不想对同一个项目多次调用 API。
我们的“生产者”给我们一个冷流来检索它:
const getHelpContentById = (id: string) => fromPromise(
httpCallToGetHelpResultFromThirdLib(id)
).pipe(
catchError(error => of({ status: 'ERROR', item: null, id })),
// extracting the body of the response
map(getHelpItemFromResponse),
// wrapping the response into an object { status: 'SUCCES', item, id }
map(item => setStatusOnHelpItem(item, id)),
startWith({ status: 'LOADING', item: null, id }),
)
Run Code Online (Sandbox Code Playgroud)
我们使用包含状态的对象启动流,然后我们收到另一个具有新状态的对象,该状态为SUCCESS或ERROR。
预期的解决方案应该:
- 在第一次调用给定 ID 时从 API 中获取
- 如果在前一个订阅完成(状态LOADING …
我知道这个问题有数千条线索。
但我发现了一些非常奇怪的事情。
如果您在 GitHub 上创建项目,请进行一些提交。
假设提交 1、2、3、4、5。
后来,您意识到要将某些内容更改为提交 3。
由于您在自己的分支中工作,因此重写历史记录没有问题。
所以让我们这样做:(基于这个stackoverflow 答案)
git rebase --interactive 'bbc643cd^'
// Modify 'pick' to 'edit' into interactive prompt and :
git commit --all --amend --no-edit
git rebase --continue
git push -f
Run Code Online (Sandbox Code Playgroud)
伟大的!错误已更正。历史已被重写,因此bbc643cd现在提交lkqjfhchc。
您可以在 GitHub 上查看源代码,一切都会更新。
但还是有人可以在 GitHub 上找到它!
访问 URL: https: //github.com/your-nickname/your-project/commit/bbc643cd ...(完整提交哈希),您就会找到它!
我们怎样才能永久删除这个提交呢?
谢谢你的帮助!
我有一个应用程序,它BehaviorSubject用作某种价值的内存存储。如果用户已登录或在用户登录期间,此值将根据 REST API 请求的结果在应用程序启动时设置。但是当用户注销时, BehaviorSubject 保持旧值。有什么方法可以根据需要清除BehaviorSubject并强制其hasValue()为假?
由于模板文字登陆 Typescript ( PR ),我们可以在我们的类型中访问以下函数:
请参阅文档了解更多信息。
知道这一点后,我怀疑我想要实现的目标是不可能的,但要询问以防万一我错过了一些东西。
我有一个界面,它有一定数量的属性......加上一些可以发展的属性。我需要能够提取出可以进化的类型。问题是它们带有增量数字(从 1 到 3)。举个例子会更好理解:
interface A {
propA: string; // not interested in that
propB: string; // not interested in that
propC: string; // not interested in that
propD1: string;
propD2: string;
propD3: string;
propE1: string;
propE2: string;
propE3: string;
propF1: string;
propF2: string;
propF3: string;
}
Run Code Online (Sandbox Code Playgroud)
不知道如何实现它或者是否可能......但我想要一个像这样的类型:
MagicType<A>应该返回'propD' | 'propE' | 'propF'.
基本上,它应该能够看到那些以1, 2,3结尾的存在。
很确定我在这里要求太多,但谁知道呢:)。
虽然这对于现有的模板文字函数( Uppercase、、、、)来说似乎不可行,但我也想知道当前是否可以创建自定义内在类型? …
这里没什么太严重的,只是好奇。
我想为某事做一个例子并想出了这段代码:
const { Observable, Subject } = Rx
const timeout$ = new Subject()
const obs$ = Observable
.of(1)
.takeUntil(timeout$)
.delay(2000)
.subscribe(x => console.log(x))
timeout$.next()
timeout$.complete()
Run Code Online (Sandbox Code Playgroud)
我以为这段代码不会显示,console.log但它确实显示了。
有人可以解释一下为什么吗?
这是一个错误还是我的理解不好takeUntil?
这是一个 Plunkr 演示https://plnkr.co/edit/wpKztBabnBeIuNZS28wu?p=info
[编辑:解决但我认为有更好的方法,如果你找到它,我仍然感兴趣]
我有一份银行清单.每个银行都包含一个帐户列表.每个帐户都包含一个操作列表.
我想在表格中显示所有操作.
这是银行名单的样子:
$scope.banks = [
{
id: 1,
name: 'bank_1',
accounts: [
{
id: 1,
name: 'account_1',
operations: [
{id: 1, name:'operation_1', price:100},
{id: 2, name:'operation_2', price:200},
{id: 3, name:'operation_3', price:300},
{id: 4, name:'operation_4', price:400}
]
},
{
id: 2,
name: 'account_2',
operations: [
{id: 5, name:'operation_5', price:100},
{id: 6, name:'operation_6', price:200},
{id: 7, name:'operation_7', price:300},
{id: 8, name:'operation_8', price:400}
]
}
]
},
{
id: 2,
name: 'bank_2',
accounts: [
{
id: 3,
name: 'account_3',
operations: [ …Run Code Online (Sandbox Code Playgroud) angular ×3
typescript ×3
rxjs ×2
angular-cli ×1
angularjs ×1
bower ×1
codeigniter ×1
git ×1
git-fork ×1
git-rebase ×1
github ×1
nestjs ×1
node.js ×1
php ×1
rx-java ×1
rxjs5 ×1
session ×1
tslint ×1