小编Hao*_* Yu的帖子

RxJS序列相当于promise.then()?

我过去经常发展很多,现在我转向RxJS.RxJS的文档没有提供关于如何从promise链到观察者序列的非常明确的例子.

例如,我通常用多个步骤编写promise链,比如

// a function that returns a promise
getPromise()
.then(function(result) {
   // do something
})
.then(function(result) {
   // do something
})
.then(function(result) {
   // do something
})
.catch(function(err) {
    // handle error
});
Run Code Online (Sandbox Code Playgroud)

我应该如何以RxJS风格重写这个承诺链?

javascript rxjs

69
推荐指数
3
解决办法
5万
查看次数

如何为md-icon正确注册font-awesome?

md-icon的文档描述了如何在几个部分中使用font-awesome,并建议我们最终可以使用font-awesome

<md-icon fontSet="fa" fontIcon="alarm"></md-icon>
Run Code Online (Sandbox Code Playgroud)

但是文档非常令人困惑,我几乎找不到通过Google为md-icon注册第三种字体集如font-awesome的例程.

任何帮助表示赞赏!

PS:我知道通常的<i>方法通常有效,但在一些最初使用md-icon的例子中似乎没有用.

angular-material2

31
推荐指数
2
解决办法
2万
查看次数

如何强制observable按顺序执行?

我正在从Promise世界转向Observable世界.我通常用Promise做的一件事就是将一系列任务链接起来并使它们按顺序运行.例如,我有三个任务:printLog1()打印1到控制台,printLog23()打印2和3到控制台,printLog4()打印4.

当我想打印1-2-3-4时,我会写一个类似的承诺链

printLog1()
  .then(() => {
    printLog23();
  })
  .then(() => {
    printLog4();
  });
Run Code Online (Sandbox Code Playgroud)

现在我想要与Observable相同的功能,我可以将printLog()函数重写为Observable

printLog1 = Rx.Observabale.of(1).map((i) => console.log(i));
printLog23 = Rx.Observabale.of(2, 3).map((i) => console.log(i));
printLog4 = Rx.Observabale.of(4).map((i) => console.log(i));
Run Code Online (Sandbox Code Playgroud)

然后我有三个observable,它们向控制台发出不同的值.如何链接它们以便这三个可观察量按顺序运行并打印1-2-3-4

rxjs rxjs5

24
推荐指数
1
解决办法
2万
查看次数

在GitLab CI中设置PostgreSQL

我正在尝试在GitLab.com上设置一个CI运行器,我想用它来运行需要PostgreSQL数据库连接的测试.CI + PostgreSQL的文档似乎过于简单,似乎告诉我们一旦提供了连接信息,就完成了数据库设置.因为我无法创建数据库,所以我可能会误解文档.我gitlab-ci.yml看起来像这样

image: node:latest

services:
  - postgres:latest

variables:
  POSTGRES_DB: rx_reactive_test
  POSTGRES_USER: rx_reactive_tester
  POSTGRES_PASSWORD: "1esdf3143"

cache:
  paths:
  - node_modules/

postgresql:
  script:
   - yarn install
   - npm test
Run Code Online (Sandbox Code Playgroud)

通过运行命令npm test`,它将运行一些将与数据库建立连接的测试.但是这些测试失败并显示错误消息

pg-reactive
  ? should build connection with the test database.
  1) should run a query returning one row.


1 passing (23ms)
1 failing

1) pg-reactive should run a query returning one row.:
   Uncaught Error: connect ECONNREFUSED 127.0.0.1:5432
    at Object.exports._errnoException (util.js:1033:11)
    at exports._exceptionWithHostPort (util.js:1056:20)
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1099:14)
Run Code Online (Sandbox Code Playgroud)

这些测试与我的本地测试数据库运行良好,因此我的CI设置一定存在问题.我会感谢任何有关我的问题的帮助:-)

postgresql gitlab-ci

13
推荐指数
1
解决办法
4800
查看次数

访问变量从RxJS subscribe()函数声明了一个组件

我能够用来this.variable访问组件的任何部分中的变量,除了在RxJS函数之外,如subscribe()catch().

在下面的示例中,我想在运行进程后打印一条消息:

import {Component, View} from 'angular2/core';

@Component({
    selector: 'navigator'
})
@View({
    template: './app.component.html',
    styles: ['./app.component.css']
})
export class AppComponent {
    message: string;

    constructor() {
        this.message = 'success';
    }

    doSomething() {
        runTheProcess()
        .subscribe(function(location) {
            console.log(this.message);
        });
    }
}
Run Code Online (Sandbox Code Playgroud)

当我跑步时doSomething(),我得到了不确定.可以使用局部变量来解决此方案:

import {Component, View} from 'angular2/core';

@Component({
    selector: 'navigator'
})
@View({
    template: './app.component.html',
    styles: ['./app.component.css']
})
export class AppComponent {
    message: string;

    constructor() {
        this.message = 'success';
    }

    doSomething() {

        // assign …
Run Code Online (Sandbox Code Playgroud)

javascript rxjs typescript arrow-functions angular

12
推荐指数
1
解决办法
1万
查看次数

如何在python中调用同一个类内的静态方法

我在同一个类中有两个静态方法

class A:
    @staticmethod
    def methodA():
        print 'methodA'

    @staticmethod
    def methodB():
        print 'methodB'
Run Code Online (Sandbox Code Playgroud)

我怎么能打电话给methodA里面methodBself似乎在静态方法中不可用.

python

9
推荐指数
2
解决办法
3593
查看次数

无法在Angular2中找到导入的commponent的模板html

我正在开发一个包含多个组件的Angular2演示.演示引导与AppComponent,我在AppComponent的模板html中导入了其他组件.我成功设置了演示并查看了AppComponent的内容,但未能加载其他组件.

这是我的angular2组件的代码示例

app.component.html

<div id="map">
    <navigator></navigator>
</div>
Run Code Online (Sandbox Code Playgroud)

app.component.ts

import {Component, View} from 'angular2/core';
import {NavigatorComponent} from '../components/navigator/navigator.component'

@Component({
    selector: 'app'
})
@View({
    templateUrl: './app/app.component.html', 
    directives: [NavigatorComponent]
})
export class AppComponent { }
Run Code Online (Sandbox Code Playgroud)

navigator.component.html

<input type="text">
Run Code Online (Sandbox Code Playgroud)

navigator.component.ts

import {Component, View} from 'angular2/core';

@Component({
    selector: 'navigator'
})
@View({
    templateUrl: './components/navigator/navigator.component.html'
})
export class NavigatorComponent { }
Run Code Online (Sandbox Code Playgroud)

当我设置服务器并尝试查看应用程序时,出现以下错误

"NetworkError: 404 Not Found - http://localhost:3000/components/navigator/navigator.component"
Run Code Online (Sandbox Code Playgroud)

Error: XHR error (404 Not Found) loading http://localhost:3000/components/navigator/navigator.component
Error loading http://localhost:3000/components/navigator/navigator.component as "../components/navigator/navigator.component" from http://localhost:3000/app/app.component.js
Run Code Online (Sandbox Code Playgroud)

显然,服务器尝试找到navigator.component,但它不存在.但是,当我尝试http:// localhost:3000/components/navigator/navigator.component.html时 …

angular

8
推荐指数
1
解决办法
7217
查看次数

无法在TypeScript中从Observable.bindNodeCallback(fs.readFile)创建observable

我试图使用rxjs 5在TypeScript中编写Node.js服务器,但是在转换fs.readFile为rxjs表单时遇到错误.我希望以下代码可以在TypeScript中使用

// This is a JavaScript example from the official documentation. It should
// also work at the TypeScript envrionment.

import * as fs from 'fs';
import { Observable } from 'rxjs';

let readFileAsObservable = Observable.bindNodeCallback(fs.readFile);

// This is the line that throws the error.
let result = readFileAsObservable('./roadNames.txt', 'utf8');

result.subscribe(x => console.log(x), e => console.error(e));
Run Code Online (Sandbox Code Playgroud)

但是,当我添加第二个参数时,我的编辑器会报告TypeScript错误 'utf-8'

Supplied parameters do not match any signature of call target.
Run Code Online (Sandbox Code Playgroud)

我试图找到如何使用fs.readFile()in rxjs和TypeScript 的指南,但没有太多运气.

rxjs typescript rxjs5

8
推荐指数
1
解决办法
2259
查看次数

如何在另一个仓库部署 github 页面

GitHub Pages 部署的文档来看,似乎可以将存储库 A 的应用程序部署到另一个存储库 B 的 github 页面。在我的用例中,我想部署到组织 github pages organization.github.io。由于组织 github pages 只接受master分支中的文件,我想在另一个 repo 上开发该应用程序。

所以在我的开发仓库(让我们称之为organization/app)中,我有这样的.travis.yml

language: node_js
node_js:
  - "node"
install:
  - npm install
script:
  - npm run lint
  - npm run build
deploy:
  provider: pages
  local-dir: dist
  github-token: $GITHUB_TOKEN
  skip-cleanup: true
  keep-history: true
  repo: organization/organization.github.io
  target-branch: master
  on:
    branch: master
Run Code Online (Sandbox Code Playgroud)

即使已经指定了repotarget-branch,Travis CI 仍然将所有构建文件部署到organization/app:gh-pages,而不是organization/organization.github.io:master.

对于真正的应用程序,请参阅此开发存储库CI 部署日志

travis-ci github-pages

5
推荐指数
1
解决办法
519
查看次数

角度/ http是angular2.js还是http.js?

这是一个愚蠢的问题,但我在其他地方看不到具体的答案.

我正在使用angular2@^2.0.0-beta.0npm安装.在node_modules/angular2/bundles/文件夹中,如果我想使用该Http服务,我应该包含angular2.jswith http.js还是angular2.js单独使用?

angular

1
推荐指数
1
解决办法
2221
查看次数