后端服务器使用gzip文件进行响应,但没有
Content-Encoding: gzip header.而且我无法控制服务器,因此无法处理问题服务器端.
我现在需要的是使用javascript解压缩gzip压缩文件客户端.
我发现这个优秀的图书馆可以帮助我做到这一点:http://nodeca.github.io/pako/
但我不想添加额外的库只是为了解压缩文件.我觉得应该有一种方法可以使用浏览器的本机功能来解压缩.我对么?如果我错了,有人可以解释为什么这个浏览器功能不作为JavaScript API公开吗?有没有办法在javascript中解压缩文件而不添加额外的库?
我试图在我的模板中使用一个observable:
<md-nav-list>
<a md-list-item *ngIf="!isAuth() | async" [routerLink]="['login']" (click)="sidenav.toggle()">Login</a>
<a md-list-item *ngIf="isAuth() | async" (click)="logout()" (click)="sidenav.toggle()">Logout</a>
</md-nav-list>
Run Code Online (Sandbox Code Playgroud)
在我的模块中:
isAuth(): Observable<boolean> {
return this.loginservice.getAuthenticated()
.map(user => { if(user){
if(user.hasOwnProperty('uid')){
return true;
} else {
return false;
}
} else {
return false;
}
})
}
Run Code Online (Sandbox Code Playgroud)
所以我的问题:
如果我登录并且observable返回true - >很酷我的菜单项出现
但如果observable返回false - >我的菜单是空的 - >什么是错的?
给定URL,例如/path/path2/path3/123;sdf=df路由配置:
{ path: 'path', data: { g: 'h' }, children: [
{ path: 'path2', data: { c: 'd' }, children: [
{ path: 'something', component: TestpageComponent, data: { a: 'b' } },
{ path: 'path3/create', component: TestpageComponent, data: { b: 'c' } },
{ path: 'path3/:id', component: TestpageComponent, data: { b: 'c' } },
] }
] },
Run Code Online (Sandbox Code Playgroud)
我需要的是找到所有段的实际配置,以便获得data所有级别(url的每个段)上的所有参数的结果集.
我可以通过例如分割段中的URL
console.log(this.router.parseUrl(url));
Run Code Online (Sandbox Code Playgroud)
或者更确切地说
console.log(this.router.parseUrl(url).root.children['primary'].segments);
Run Code Online (Sandbox Code Playgroud)
将返回
[{"path":"path","parameters":{}},{"path":"path2","parameters":{}},{"path":"and","parameters":{}},{"path":"123","parameters":{"sdf":"df"}}]
Run Code Online (Sandbox Code Playgroud)
因此,将URL拆分为段不是问题.但是我需要为每个段获取配置.
我可以获得所有路线的实际配置
console.log(this.router.config);
Run Code Online (Sandbox Code Playgroud)
我可以用段经过配置树,并找出我需要的分支,但它可能会导致,例如同时解决烦恼:id针对create段.所以,我想使用路由器解析配置的 …
我是Angular和Angular Material的新手,现在我在一些项目中担任支持.有一个带过滤器和一个复选框的网格,用于检查网格中的用户是处于活动状态,非活动状态还是未选择状态.只有两个选项(活动,非活动)会更简单,但是,我必须为它制作3个状态:
以下是官方Angular Material文档中的复选框示例:https://stackblitz.com/angular/rxdmnbxmkgk? file = app%2Fcheckbox-configurable- example.html
如何以最简单的方式制作它?
我希望我的FormControl( FormGroup/ FormArray) 是强类型的,所以当我有例如
interface SomeSource {
id: string;
name: string;
}
Run Code Online (Sandbox Code Playgroud)
我把它变成了例如
let form = new FormGroup<SomeSource>({
id: new FormControl('test id'),
name1: new FormControl('test name')
});
Run Code Online (Sandbox Code Playgroud)
TypeScript 抛出了一个错误:在name上找不到FormGroup。
同样在理想的世界中form.value应该是SomeSource类型(而不是any)。
问题是没有办法为任何AbstractFormControl孩子指定这个泛型类型。
我认为这很容易FormGroup用自己的界面覆盖。但是,有没有办法仅使用 Angular 来实现这一目标?如果没有,是否有第三方解决方案?
动机:我想轻松重构我的SomeSource. 目前,当我重构SomeSource界面时,表单未适配且未抛出错误 => 存在一些错误的空间。
我有排队jQuery Date Picker的当前代码:
function register_my_scripts()
{
wp_register_script('scripts', plugins_url('/js/scripts.js', __FILE__));
wp_enqueue_script('scripts');
wp_enqueue_script('jquery-ui-datepicker');
}
function register_my_styles()
{
wp_enqueue_style('e2b-admin-ui-css','http://ajax.googleapis.com/ajax/libs/jqueryui/1.9.0/themes/base/jquery-ui.css',false,"1.9.0",false);
}
add_action('wp_enqueue_scripts', 'register_my_scripts');
add_action('wp_enqueue_scripts', 'register_my_styles');
Run Code Online (Sandbox Code Playgroud)
在scripts.js中的jQuery函数:
jQuery(document).ready(function(){
jQuery('.datepicker').datepicker({
dateFormat : 'D, m/d/yy'
});
});
Run Code Online (Sandbox Code Playgroud)
和html字段:
<input type="text" class="datepicker"/>
Run Code Online (Sandbox Code Playgroud)
这段代码在前端工作正常,但是由于某种原因在后端没有任何作用。我只需要它在后端工作。
这里发生了什么?
我怎样才能获得模块内的模块路径?我使用 babel 和 webpack 为浏览器创建包。
我预计
/src/someModule/index.js
console.log(`someModule path is ${process.execPath}`);
Run Code Online (Sandbox Code Playgroud)
在浏览器中输出 someModule path is /home/user/proj/src/someModule
或者 someModule path is /src/someModule
有一个组件封装了一些库.为了避免所有这些库的事件监听器的变化检测噩梦,该库的范围在角区域之外:
@Component({ ... })
export class TestComponent {
@Output()
emitter = new EventEmitter<void>();
constructor(private ngZone: NgZone) {}
ngOnInit() {
this.ngZone.runOutsideAngular(() => {
// ...
});
}
}
Run Code Online (Sandbox Code Playgroud)
这一切都非常清楚和普遍.现在让我们添加事件来发出动作:
@Component({ ... })
export class TestComponent {
@Output()
emitter = new EventEmitter<void>();
private lib: Lib;
constructor(private ngZone: NgZone) {}
ngOnInit() {
this.ngZone.runOutsideAngular(() => {
this.lib = new Lib();
});
this.lib.on('click', () => {
this.emitter.emit();
});
}
}
Run Code Online (Sandbox Code Playgroud)
问题是这个发射器不会触发变化检测,因为它是在区域外触发的.那么有可能重新进入该区域:
@Component({ ... })
export class TestComponent {
@Output()
emitter = new EventEmitter<void>();
private lib: …Run Code Online (Sandbox Code Playgroud) 我即将模拟一个包含在observable中的http调用.我最初的想法是简单地使用Observable.of类似的Promise.resolve,但它似乎没有像我预期的那样工作:
Rx.Observable.of('of1').subscribe(e => console.log(e));
console.log('of2');
Rx.Observable.from(Promise.resolve('from1')).subscribe(e => console.log(e));
console.log('from2');Run Code Online (Sandbox Code Playgroud)
<script src="https://npmcdn.com/@reactivex/rxjs@5.0.0-beta.6/dist/global/Rx.umd.js"></script>Run Code Online (Sandbox Code Playgroud)
它似乎在异步Observable.of运行时同步Rx.Observable.from(Promise.resolve('from1'))运行(这就是我想要的).只要我想测试微调器显示,同步调用对我来说不是一个选项.
当我延迟它或设置一个计时器时,有某种解决方案:
Rx.Observable.of('of1').delay(0).subscribe...
Run Code Online (Sandbox Code Playgroud)
但这对我来说也不好看.
如何转向Observable.of异步运行?将它从Promise转换似乎是一种矫枉过正.
更新
找到解决方案后,我根据接受的答案编写了一个小助手ng2-rx-collector,使其更易于使用.希望它可以帮助一个人一次又一次地面对同样的问题.
原始问题
假设我们在hot observables上有一个包含两个订阅的组件.我们订阅它们ngOnInit并取消订阅ngOnDestroy以避免内存泄漏/意外行为:
public ngOnInit() {
this.s1 = o1.subscribe(console.debug.bind(console));
this.s2 = o2.subscribe(console.debug.bind(console));
}
public ngOnDestroy() {
this.s1.unsubscribe();
this.s2.unsubscribe();
}
Run Code Online (Sandbox Code Playgroud)
我喜欢Rx,但每次我需要遵循这个时,我真的想要自杀:
有没有办法改善这个?
例如在RxSwift中他们有一个DisposeBag为了改进过程,翻译成打字稿将是:
private let bag = DisposeBag();
...
o1.subscribe(...).addDisposableTo(bag);
Run Code Online (Sandbox Code Playgroud)
然后只破坏它一次.问题是我找不到任何类似的Subscription功能.
任何想法/提示都会受到热烈欢迎.
angular ×5
typescript ×5
javascript ×4
rxjs5 ×2
angularfire2 ×1
asynchronous ×1
datepicker ×1
es6-modules ×1
gzip ×1
jquery ×1
observable ×1
rxjs ×1
webpack ×1
wordpress ×1