小编apr*_*ity的帖子

如何等待RxJS内部订阅方法

在RxJS主题的​​订阅回调中,我想要await一个async函数.下面是打字稿发布者抱怨说的代码示例:

错误:(131,21)TS2304:找不到名称'await'.

async ngOnInit() {
  this.subscriber = dateSubscription.subscribe((date: Date) => {
    let dbKey = await this._someService.saveToDatabase(someObject);
    // wait for db write to finish before evaluating the next code
    // ... some other code here
  });
}
Run Code Online (Sandbox Code Playgroud)

通常我在尝试在非async函数内调用await时会看到这个.我是否需要进行订阅回调async或者我是否会犯这个错误?该函数saveToDatabaseasync并返回一个解析为写入的数据库主键的promise.

async-await rxjs typescript angular

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

允许swagger查询参数为字符串或整数数组

在使用swagger2(openAPI)构建rest api时,我想允许查询参数station_id支持以下内容:

  • ?station_id = 23(返回站23)
  • ?station_id = 23,45(返回站23和45)
  • ?station_id = [3:14](返回站3到14)
  • ?station_id = 100%(%s用作通配符,因此返回诸如1001、10049等的信息。)

我使用下面的大方定义(字符串数组)来尝试完成此操作:

parameters:
  - name: station_id
    in: query
    description: filter stations by station_id
    required: false
    type: array
    items:
      type: string
Run Code Online (Sandbox Code Playgroud)

使用此定义,除?station_id = 23以外,所有其他示例均适用,因为挥舞性验证失败并显示以下消息:

{
  "message": "Validation errors",
  "errors": [
    {
      "code": "INVALID_REQUEST_PARAMETER",
      "errors": [
        {
          "code": "INVALID_TYPE",
          "params": [
            "array",
            "integer"
          ],
          "message": "Expected type array but found type integer",
          "path": [],
          "description": "filter stations by station_id"
        }
      ],
      "in": "query",
      "message": "Invalid parameter (station_id): Value failed …
Run Code Online (Sandbox Code Playgroud)

node.js swagger swagger-2.0 openapi

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

Angular2 + Webpack UncaughtReferenceError __decorate未定义

在尝试将有效的angular2打字稿应用程序迁移到webpack后,我得到以下运行时错误

app.js:38016Uncaught ReferenceError: __decorate is not defined
Run Code Online (Sandbox Code Playgroud)

它爆炸的线上的代码看起来像这样

NpnPortalService = __decorate([
            core_1.Injectable(), 
            __metadata('design:paramtypes', [http_1.Http])
        ], NpnPortalService);
Run Code Online (Sandbox Code Playgroud)

我做构建时Webpack没有抱怨,我没有看到任何打字稿编译错误.这是我的webpack.config.js

module.exports = {
    entry: {
        app: "./app/boot",
        polyfills: ['./node_modules/es6-shim/es6-shim.min.js', './node_modules/zone.js/dist/zone.min.js']
    },
    output: {
        path: __dirname + '/dist',
        filename: "[name].js"
    },
    resolve: {
        extensions: ['', '.js', '.ts']
    },
    module: {
        loaders: [{
            test: /\.ts/, loader: 'ts-loader', exclude: /node_modules/
        }],
        noParse: [ './node_modules/es6-shim/es6-shim.min.js' ]
    }
};
Run Code Online (Sandbox Code Playgroud)

这是我的tsconfig.js

{
  "compilerOptions": {
    "target": "es5",
    "module": "commonjs",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "sourceMap": true,
    "noEmitHelpers": true
  },
  "files": [ …
Run Code Online (Sandbox Code Playgroud)

webpack angular

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

nativescript项目中的两个package.json文件

不知何故,我的nativescript项目中有两个package.json文件.我应该有两个吗?如果没有,任何想法为什么他们都会在那里?根据这个页面,我猜我可以删除app文件夹中的package.json文件?我很确定我只从项目的根目录运行了npm install.有时候我也会在项目的根目录下运行tns install.

my-project
    ??? app
    ?   ??? package.json <-- can I delete this?
    ??? package.json
    ??? node_modules
    ??? platforms
        ??? android
        ??? ios
Run Code Online (Sandbox Code Playgroud)

npm nativescript

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

注入页面为空

将 angular nativescript 项目升级到 angular、typescript、tns 等的当前版本后。我收到一个运行时错误,指出:

类型错误:无法在新的 AppComponent 中将属性“actionBarHidden”设置为 null...

以前用于隐藏操作栏的代码如下所示:

import {Page} from "tns-core-modules/ui/page";

export class AppComponent implements OnInit, AfterViewInit {

    constructor(page: Page) {
        page.actionBarHidden = true;
    }
}
Run Code Online (Sandbox Code Playgroud)

为什么注入后页面为空?

nativescript angular2-nativescript

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

NativeScriptException:找不到模块:"stream"

升级了我的package.json中的一些项目后,我突然得到:

Error: com.tns.NativeScriptException: Failed to find module: "stream", relative to: /app/tns_modules/

StackTrace: 
    Frame: function:'require', file:'', line: 1, column: 266
    Frame: function:'', file:'/data/data/org.nativescript.naturesnotebookmobile/files/app/tns_modules/parse5/lib/parser/stream.js', line: 3, column: 22
Run Code Online (Sandbox Code Playgroud)

有任何想法吗?以前我所有角度的东西都是2.0.0,然后就可以了.这是我的package.json:

{
  "dependencies": {
    "@angular/common": "2.1.0",
    "@angular/compiler": "2.1.0",
    "@angular/core": "2.1.0",
    "@angular/forms": "2.1.0",
    "@angular/http": "2.1.0",
    "@angular/platform-browser": "2.1.0",
    "@angular/platform-browser-dynamic": "2.1.0",
    "@angular/platform-server": "2.1.0",
    "@angular/router": "3.1.0",
    "crypto-js": "^3.1.7",
    "nativescript-angular": "1.1.0",
    ... a few other things here...
    "node-geocoder": "^3.15.0",
    "oauth-signature": "^1.3.1",
    "reflect-metadata": "^0.1.8",
    "tns-core-modules": "2.3.0",
    "util": "^0.10.3"
  },
  "devDependencies": {
    "babel-traverse": "6.16.0",
    "babel-types": "6.16.0",
    "babylon": "6.12.0",
    "lazy": "1.0.11",
    "nativescript-dev-typescript": …
Run Code Online (Sandbox Code Playgroud)

nativescript angular2-nativescript

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