小编Her*_*sen的帖子

由于打字,TypeScript编译错误

我使用的是typescript 1.7.5,类型为0.6.9,角度为2.0.0-beta.0.

如何解决Duplicate identifier由于打字定义文件而导致的打字稿编译错误消息?

Duplicate identifier错误发生在以下目录的定义文件中:

node_modules/angular2/typings/es6-shim/es6-shim.d.ts
node_modules/angular2/typings/jasmine/jasmine.d.ts
node_modules/angular2/typings/zone/zone.d.ts
typings/browser/ambient/es6-promise/es6-promise.d.ts
typings/browser/ambient/es6-shim/es6-shim.d.ts
typings/browser/ambient/jasmine/jasmine.d.ts
typings/browser/ambient/karma/karma.d.ts
typings/browser/ambient/zone.js/zone.js.d.ts
Run Code Online (Sandbox Code Playgroud)

编译器在node_modules/angular2目录中做了什么,因为我将其排除在外tsconfig.json

我也在GitHub上发布了这个问题

tsconfig.json

{
    "compilerOptions": {
        "target": "es5",
        "module": "system",
        "moduleResolution": "node",
        "sourceMap": true,
        "emitDecoratorMetadata": true,
        "experimentalDecorators": true,
        "removeComments": false,
        "noImplicitAny": false
    },
    "exclude": [
        "node_modules",
        "typings/main",
        "typings/main.d.ts"
    ]
}
Run Code Online (Sandbox Code Playgroud)

如果我改变了exclude部分tsconfig.json:

"exclude": [
    "node_modules",
    "typings"
]
Run Code Online (Sandbox Code Playgroud)

但是在添加以下内容之后我又得到了相同的Duplicate identifier编译错误:

/// <reference path="../../typings/browser.d.ts" />
Run Code Online (Sandbox Code Playgroud)

typings.json

{
  "name": "example-mean-app-client",
  "dependencies": {},
  "devDependencies": {},
  "ambientDependencies": { …
Run Code Online (Sandbox Code Playgroud)

typing typescript

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

Angular2 @ TypeScript Observable错误

我有一个输入字段,当用户键入搜索字符串时,我想等待用户在执行_heroService http请求之前停止键入至少300毫秒(去抖动).只有更改的搜索值才能通过服务(distinctUntilChanged).switchMap返回一个新的observable,它结合了这些_heroService observable,在原始请求顺序中重新排列它们,并仅向订阅者提供最新的搜索结果.

我使用的是Angular 2.0.0-beta.0和TypeScript 1.7.5.

我怎样才能使这个东西正常工作?

我得到编译错误:

Error:(33, 20) TS2345: Argument of type '(value: string) => Subscription<Hero[]>' is not assignable to parameter of type '(x: {}, ix: number) => Observable<any>'.Type 'Subscription<Hero[]>' is not assignable to type 'Observable<any>'. Property 'source' is missing in type 'Subscription<Hero[]>'.
Error:(36, 31) TS2322: Type 'Hero[]' is not assignable to type 'Observable<Hero[]>'. Property 'source' is missing in type 'Hero[]'.
Run Code Online (Sandbox Code Playgroud)

运行时错误(在搜索输入字段中键入第一个键后):

EXCEPTION: TypeError: unknown type returned
STACKTRACE:
TypeError: unknown type returned
at Object.subscribeToResult (http://localhost:3000/rxjs/bundles/Rx.js:7082:25)
at SwitchMapSubscriber._next (http://localhost:3000/rxjs/bundles/Rx.js:5523:63) …
Run Code Online (Sandbox Code Playgroud)

http observable rxjs typescript angular

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

Angular 5缓存http服务api调用

在我的Angular 5应用程序中,在应用程序的不同位置需要多次某个数据集(不经常更改).调用API后,结果将与Observable do运算符一起存储.这样我在我的服务中实现了HTTP请求的缓存.

我正在使用Angular 5.1.3和RxJS 5.5.6.

这是一个好习惯吗?还有更好的选择吗?

import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/observable/of';
import 'rxjs/add/operator/do';

@Injectable()
export class FruitService {

  fruits: Array<string> = [];

  constructor(private http: HttpClient) { }

  getFruits() {
    if (this.fruits.length === 0) {
      return this.http.get<any>('api/getFruits')
        .do(data => { this.fruits = data })
    } else {
      return Observable.of(this.fruits);
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

angular angular-httpclient

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

WebRTC 在 iOS Safari 上的 Angular 5 中不起作用

我正在使用 WebRTC 构建一个应用程序,但它在 iOS Safari 上的 Angular 5 中不起作用。我使用原生 WebRTC API,没有框架。

首先没有 Angular

为了证明我的观点 Angular 是问题所在,我使用纯 html 和 javascript 进行了 WebRTC 测试。所以我有一个index.html和一个my-webrtc.js

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">    
  <title>WebRTC Test</title>
</head>
<body>
  <div>
    <video id="local-video" playsinline autoplay muted></video>
    <video id="remote-video" playsinline autoplay></video>
  </div>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.0.4/socket.io.js"></script>  
  <script src="https://webrtc.github.io/adapter/adapter-latest.js"></script>
  <script src="js/my-webrtc.js"></script>
</body>
</html> 
Run Code Online (Sandbox Code Playgroud)

我将这两个文件放在 TSL/SSL 安全网络服务器上。在同一台服务器上,我安装了一个基本的信令服务器。my-webrtc.js一切尽在其中:发信号、提供、回答、冻结候选以及将流连接到 HTML 元素。

对于所有测试,我仅使用 LAN 来确保不需要 STUN 或 TURN。

检测结果

在这些经过测试的情况下一切正常:

  • 桌面/Chrome <-> 桌面/Chrome
  • 桌面/Chrome <-> 桌面/Firefox
  • 桌面/Chrome <-> 桌面/Safari
  • 桌面/Chrome …

safari ios webrtc zonejs angular

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

Ubuntu 上的配置 CoTurn 不起作用

在使用 Chrome 62.0.3202.89 的 MacBook 10.12.6 上使用 Trickle ICE 测试 STUN & TURN 服务器 (CoTurn) 时,我没有得到任何候选者:

\n\n

https://webrtc.github.io/samples/src/content/peerconnection/trickle-ice/

\n\n

和:

\n\n
stun:<ip-adres>:3478\nturn:<ip-adres>:3478 [username:test]    \n
Run Code Online (Sandbox Code Playgroud)\n\n

在 Digital Ocean 上,我创建了一个 Droplet Ubuntu 16.04.3 x64 并安装了 CoTurn 版本 4.5.0.3,执行以下操作:

\n\n
sudo apt-get update\nsudo apt-get install coturn\n
Run Code Online (Sandbox Code Playgroud)\n\n

默认情况下,防火墙处于非活动状态。

\n\n

接下来,我编辑sudo vi /etc/turnserver.conf并给出以下选项:

\n\n
fingerprint\nlt-cred-mech\nuser=username:test\nrealm=<ip-adres>\nlistening-ip=<ip-adres>\nrelay-ip=<ip-adres>\nexternal-ip=<ip-adres>\n
Run Code Online (Sandbox Code Playgroud)\n\n

接下来,我编辑sudo vi /etc/default/coturn并取消注释该选项:

\n\n
TURNSERVER_ENABLED=1\n
Run Code Online (Sandbox Code Playgroud)\n\n

然后我启动 Coturn 守护进程:

\n\n
sudo systemctl start coturn\nsudo systemctl status coturn\n
Run Code Online (Sandbox Code Playgroud)\n\n

这给出了输出:

\n\n
\xe2\x97\x8f coturn.service - …
Run Code Online (Sandbox Code Playgroud)

ubuntu stun webrtc turn coturn

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

在 Ubuntu 16.04.3 x64 TLS 上安装 CoTurn 4.5.0.6 不起作用

我正在尝试在 Digital Ocean Ubuntu 16.04.3 LTS 上安装 CoTurn 4.5.0.6。我无法使用,sudo apt-get install coturn因为它安装了 4.5.0.3 版。我也无法安装 Ubuntu 17.10,因为我需要长期支持 (TLS)。

我使用 Ubuntu 16.04.3 LTS 在 Digital Ocean 上创建了一个 Droplet。然后我下载了 CoTurn:

wget https://github.com/coturn/coturn/archive/4.5.0.6.tar.gz
Run Code Online (Sandbox Code Playgroud)

我打开它:

tar xvfz 4.5.0.6.tar.gz
Run Code Online (Sandbox Code Playgroud)

进入文件夹:

cd coturn-4.5.0.6
Run Code Online (Sandbox Code Playgroud)

安装所需的库和实用程序:

sudo apt-get install libssl-dev
sudo apt-get install sqlite3
sudo apt-get install libsqlite3-dev
sudo apt-get install libevent-dev
sudo apt-get install libpq-dev
sudo apt-get install mysql-client
sudo apt-get install libmysqlclient-dev
sudo apt-get install libhiredis-dev
Run Code Online (Sandbox Code Playgroud)

最后一个报错:E: Unable to locate package libhiredis-dev

在那之后运行: …

ubuntu stun webrtc turn coturn

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

当用户停止输入时,Angular2 @ TypeScript错误rxjs/Subject :: filtering

我使用的是Angular 2.0.0-beta.0和TypeScript 1.7.5.在尝试更改聪明的过滤器时:

https://angular.io/docs/ts/latest/guide/server-communication.html#!#more-observables

"聪明"过滤器应该只在用户停止输入时执行某些操作.

我得到编译错误:

Error:(30, 20) TS2345: Argument of type '(term: string) => void' is not assignable to parameter of type '(x: {}, ix: number) => Observable<any>'. Type 'void' is not assignable to type 'Observable<any>'.
Run Code Online (Sandbox Code Playgroud)

运行时错误:

EXCEPTION: Error during instantiation of Test!.  
ORIGINAL EXCEPTION: TypeError: this._searchTermStream.debounceTime is not a function
Run Code Online (Sandbox Code Playgroud)

test.ts

import {bootstrap} from 'angular2/platform/browser';
import {Component} from 'angular2/core';
import {Observable}        from 'rxjs/Observable';
import {Subject}           from 'rxjs/Subject';

@Component({
    selector: 'my-app',
    template: `
        <h3>Test</h3>
        Filter basic <input #filterBasic (keyup)="searchBasic(filterBasic.value)"/><br> …
Run Code Online (Sandbox Code Playgroud)

rxjs typescript angular

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

Angular2如何清空可观察流

我使用的是Angular 2.0.0-beta.0和TypeScript 1.7.5

当您在搜索框中键入内容并在屏幕上找到并显示某些内容时,您将删除搜索输入框,并且您希望显示一个空列表.它使用这段代码工作: this.searchTermStream.next("makesureyoudontfindanything");

没有做http请求,有没有人有更好的清洁解决方案?

@Component({
    selector: 'contact-search',
    template: `
        <div class="container">
            <div class="form-group">
                <label for="inputUser">Search</label>
                <input #inputUser (keyup)="search(inputUser.value)">
            </div>
            <ul>
                <li *ngFor="#contact of contactList | async">{{contact.name}}</li>
            </ul>
        </div>
    `
})

export class ContactSearch {

    private searchTermStream = new Subject<string>();

    private contactList: Observable<Contact[]> = this.searchTermStream
        .debounceTime(300)
        .distinctUntilChanged()
        .switchMap((value: string) => this.contactService.searchContacts(value))

    constructor(private contactService: ContactService) {}

    search(value: string) {
        if (value) {
            this.searchTermStream.next(value);
        }
        else {
            this.searchTermStream.next("makesureyoudontfindanything");
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

http observable typescript angular

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

WebRTC无法将Safari与Chrome for Android连接

WebRTC无法将Safari与Chrome for Android连接.从Chrome桌面到Safari,没有任何问题.Safari - Safari也没有问题.

自iOS 11和桌面上的Safari 11以来,Apple本身就支持WebRTC.

作为基础,我使用谷歌codelab的代码,我在两个浏览器之间有一个基本的视频聊天应用程序.为了测试我在同一个WiFi网络中使用了两个设备,只是为了确保.

它的工作原理在这些情况下(见规格的设备):

  • 桌面/ Chrome < - >桌面Safari
  • 桌面/ Chrome < - > Android/Tab/Chrome
  • 桌面/ Chrome < - > iPad/Safari
  • 桌面/ Chrome < - > iPhone/Safari
  • 桌面/ Safari < - > iPad/Safari
  • 桌面/ Safari < - > iPhone/Safari
  • iPad/Safari < - > iPhone/Safari

不适用于这些情况:

  • Android/Tab/Chrome < - > iPad/Safari
  • Android/Tab/Chrome < - > iPhone/Safari
  • Android/Tab/Chrome < - >桌面/ Safari

设备规格:

桌面/ Chrome
- Macbook MacOS 10.12.6
- …

safari android google-chrome ios webrtc

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