小编Fer*_*qui的帖子

如何使用ngFor循环迭代包含键作为字符串和值作为映射迭代

我是角度5的新手,并试图在打字稿中迭代包含另一张地图的地图.如何在下面的角度下面迭代这种地图是组件的代码:

import { Component, OnInit} from '@angular/core';

@Component({
  selector: 'app-map',
  templateUrl: './map.component.html',
  styleUrls: ['./map.component.css']
})
export class MapComponent implements OnInit {
  map = new Map<String, Map<String,String>>();
  map1 = new Map<String, String>();

  constructor() { 


  }

  ngOnInit() {
    this.map1.set("sss","sss");
    this.map1.set("aaa","sss");
    this.map1.set("sass","sss");
    this.map1.set("xxx","sss");
    this.map1.set("ss","sss");


    this.map1.forEach((value: string, key: string) => {
      console.log(key, value);

    });


    this.map.set("yoyoy",this.map1);

  }



}
Run Code Online (Sandbox Code Playgroud)

它的模板html是:

<ul>
  <li *ngFor="let recipient of map.keys()">
    {{recipient}}
   </li>


</ul>

<div>{{map.size}}</div>
Run Code Online (Sandbox Code Playgroud)

运行时错误

typescript angular-cli angular

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

由于require-from-string而使用npm安装Angular时出错

如何解决此错误,因为我无法安装Angular.

请参阅以下例外:

C:\Users\absin\node>npm install -g @angular/cli
npm ERR! code ETARGET
npm ERR! notarget No matching version found for require-from-string@^1.1.0
npm ERR! notarget In most cases you or one of your dependencies are requesting
npm ERR! notarget a package version that doesn't exist.
npm ERR! notarget
npm ERR! notarget It was specified as a dependency of 'cosmiconfig'
npm ERR! notarget

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\absin\AppData\Roaming\npm-cache\_logs\2018-01-06T19_07_00_000Z-debug.log
Run Code Online (Sandbox Code Playgroud)

即使在时间解决之后:

npm install https://github.com/floatdrop/require-from-string/tarball/v1.1.0 --save
npm …
Run Code Online (Sandbox Code Playgroud)

install node.js angular-cli angular

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

如何在角度为5的Component中格式化日期

我是角色的新手,并希望在组件ngOnInit方法中格式化日期.我已经看到一些示例,其中管道运算符用于格式化数据,但我不知道如何格式化组件文件中的日期.

下面是代码

export class DashboardComponent implements OnInit {
  formatdate = 'dd/MM/yyyy';
  constructor(private auth: AuthService) { }

  ngOnInit() {
    console.log(new Date().toISOString())
  }


}
Run Code Online (Sandbox Code Playgroud)

angular-cli angular

15
推荐指数
4
解决办法
7万
查看次数

Angular 5如何将字符串作为HTML元素插入

我从服务器获得响应字符串:

<table><thead><tr> <th scope="col">Home</th> <th scope="col">Page </th> <th scope="col">World </th> <th scope="col">HE </th> <th scope="col">MAN</th> <th scope="col">GO</th></tr></thead><tbody><tr><td>1</td><td>2</td><td>3</td><td>1</td><td>145</td><td>42</td></tr><tr><td>12</td><td>3125</td><td>315</td><td>2554</td><td>5542</td><td>331255</td></tr></tbody></table>
Run Code Online (Sandbox Code Playgroud)

我怎么能直接在我的页面中插入这个html元素,以便我可以查看用户的html表.

我是新的角度下面是我尝试过的东西:

我在我的componentsnet类中创建了一个变量作为htmltable,并试图创建一个如下所示的htmlelemnt

this.htmltable = document.createElement(serverresponse.htmltable)
Run Code Online (Sandbox Code Playgroud)

但它不起作用.

我也尝试过这种方式:

 <div class="dynamically_created_div unique_identifier" #d1></div>
    @ViewChild('d1') d1:ElementRef;
        this.renderer.appendChild(this.d1, serverresponse.htmltable);
Run Code Online (Sandbox Code Playgroud)

但它不起作用.请建议我这样做的正确方法

angular angular5

8
推荐指数
3
解决办法
7524
查看次数

Visual Studio Code 窗口崩溃

我在 Visual Studio 代码中收到以下错误:

视觉工作室错误

当我单击“重新打开”时,此警报不断出现,不允许我在编辑器中编写代码。我已卸载并重新安装 Visual Studio Code,但仍然显示此错误。

visual-studio-code

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

BottomSheet Fragment底部工作表布局中存在的NestedScrollview中的滚动行为问题

我的场景是按钮点击我需要打开一个底部展开的底部,当我们向上拖动时它应该像collasping工具栏一样.

这里Appbar的行为与Bottomsheet同步,但不知何故,NestedScrollview行为只与Collasping工具栏同步,而不是Bottomsheet行为.

当我在NestedScrollview上滚动它只是扩展和压缩工具栏而不是BottomSheet.

下面是底部布局:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:fitsSystemWindows="true"
    android:layout_width="match_parent"
    android:elevation="@dimen/design_appbar_elevation"
    android:layout_height="match_parent"
    app:layout_behavior="@string/bottom_sheet_behavior"

    app:behavior_hideable="true"

    >

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appbar"
        android:fitsSystemWindows="true"
        android:layout_height="192dp"
        android:layout_width="match_parent"

        >

        <android.support.design.widget.CollapsingToolbarLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:toolbarId="@+id/toolbar"
            app:layout_scrollFlags="scroll|exitUntilCollapsed|snap"
            android:fitsSystemWindows="true"

            app:contentScrim="?attr/colorPrimary">

            <ImageView
                android:id="@+id/app_bar_image"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                app:layout_collapseMode="parallax"
                android:src="@drawable/ic_launcher_background"
                android:scaleType="centerCrop" />

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_height="?attr/actionBarSize"
                android:layout_width="match_parent">


            </android.support.v7.widget.Toolbar>
        </android.support.design.widget.CollapsingToolbarLayout>
    </android.support.design.widget.AppBarLayout>

    <android.support.v4.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scrollbars="none"

        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        >

        <android.support.constraint.ConstraintLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:minHeight="300dp">

            <EditText
                android:id="@+id/editText"
                android:layout_width="222dp"
                android:layout_height="wrap_content"
                android:layout_marginStart="8dp"
                android:layout_marginTop="8dp"
                android:layout_marginEnd="8dp"
                android:ems="10"
                android:inputType="textPersonName"
                android:text="Name"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent" />

            <EditText
                android:id="@+id/editText2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="8dp"
                android:ems="10"
                android:inputType="textPersonName"
                android:text="Name"
                app:layout_constraintEnd_toEndOf="@+id/editText"
                app:layout_constraintStart_toStartOf="@+id/editText" …
Run Code Online (Sandbox Code Playgroud)

android android-appbarlayout android-nestedscrollview bottom-sheet android-bottom-nav-view

6
推荐指数
0
解决办法
1254
查看次数

如何跟踪 Angular HTTP POST 调用进度

我试图在我的 http 调用中放置一个进度条,但是我无法发出同步 HTTP 调用请求,而是以异步方式进行。

下面是进行http调用的函数

 public authenticationt2cHTTP(email, password) {
    console.log("authenticationt2cHTTP WITH HEADERS");
    const body = new HttpParams()
      .set('email', email)
      .set('password', password);
    const req = new HttpRequest('POST', 'http://192.168.0.135:8080/rest/auth/login', body, {
      reportProgress: true,
      headers: new HttpHeaders().set('Content-Type', 'application/x-www-form-urlencoded')
    });

    this.http.request(req).subscribe(event => {
      // Via this API, you get access to the raw event stream.
      // Look for upload progress events.
      if (event.type === HttpEventType.UploadProgress) {
        // This is an upload progress event. Compute and show the % done:
        const percentDone = Math.round(100 …
Run Code Online (Sandbox Code Playgroud)

angular-cli angular

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

如何在角度5中的ngOnInit上调用NgbCarousel的pause()函数

我是 Angular 的新手,并在我的用户界面中使用 ngbootstrap 。默认情况下,我无法在暂停模式下加载 NgbCarousel。下面是我尝试过的代码

    import { Component, OnInit, ViewChild } from '@angular/core';
    import { NgbCarousel } from '@ng-bootstrap/ng-bootstrap';
    @Component({
      selector: 'app-dashboard',
      templateUrl: './dashboard.component.html',
      styleUrls: ['./dashboard.component.css'],
      providers: [NgbCarousel] // add NgbCarouselConfig to the component providers

    })
     export class DashboardComponent implements OnInit {

    constructor(private auth: AuthService, private ngbCarousel: NgbCarousel) {}
    ngOnInit() {
        this.ngbCarousel.pause();
    }
    }
Run Code Online (Sandbox Code Playgroud)

下面是html文件:

<div class="jumbotron">
  <div class="container">
    <div class="row">
      <div class="col-12 col-lg-9">
        <ngb-carousel>
          <ng-template ngbSlide>
            <img src="https://lorempixel.com/900/500?r=1" alt="Random first slide">
            <div class="carousel-caption">
              <h3>First slide label</h3>
              <p>Nulla vitae …
Run Code Online (Sandbox Code Playgroud)

angular-cli ng-bootstrap angular

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

Chrome 扩展:在后台 JS 中录制麦克风和扬声器

根据最新更新,在后台 js 中捕获麦克风和扬声器音频以进行实时音频处理的正确方法是什么。我被困在这个我已经尝试了所有媒体记录器 api、记录 js api 和 chrome 桌面捕获,但所有这些都返回麦克风音频。他们都无法捕获扬声器的音频。请提出一种实现此场景的方法

以下是捕获麦克风但不捕获扬声器的示例代码:

var audioChunks;
startRecord.onclick = e => {
  startRecord.disabled = true;
  stopRecord.disabled=false;
  // This will prompt for permission if not allowed earlier
  navigator.mediaDevices.getUserMedia({audio:true})
    .then(stream => {
      audioChunks = []; 
      rec = new MediaRecorder(stream);
      rec.ondataavailable = e => {
        audioChunks.push(e.data);
        if (rec.state == "inactive"){
          let blob = new Blob(audioChunks,{type:'audio/x-mpeg-3'});
          recordedAudio.src = URL.createObjectURL(blob);
          recordedAudio.controls=true;
          recordedAudio.autoplay=true;
          audioDownload.href = recordedAudio.src;
          audioDownload.download = 'mp3';
          audioDownload.innerHTML = 'download';
       }
      }
    rec.start();  
    })
    .catch(e=>console.log(e));
}
stopRecord.onclick = e …
Run Code Online (Sandbox Code Playgroud)

javascript audio-recording google-chrome-extension

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

Xcode如何在水平堆栈视图中创建方形按钮(宽度等于高度)

我需要在页面底部创建3个方形按钮.所有这些都必须对齐,尺寸应该是正方形.

到目前为止,我已经创建了一个水平堆栈视图,并创建了autolayout约束50从左边,50从右边,10从底部约束,并将stackview高度设置为60.

如何创建方形按钮,因为stackview子视图宽度是动态的并且在运行时确定?

如何为这三个按钮设置相等的宽高比?

由于高度不合适导致的圆形图像问题

ios swift uistackview

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

Android 一加 6(Android 派版)BOOT COMPLETE 广播接收器不工作

Android 一加 6(Android 派版)BOOT COMPLETE 广播接收器不工作

 <receiver
            android:name=".service.ConnectionReceiver"
            android:enabled="true" android:exported="true"
            >
            <intent-filter>
                <action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
                <action android:name="android.net.conn.ACTION_BOOT_COMPLETED" />
                <action android:name="android.intent.action.BOOT_COMPLETED" />
                <action android:name="android.intent.action.QUICKBOOT_POWERON"/>
            </intent-filter>
        </receiver>
Run Code Online (Sandbox Code Playgroud)

下面是我的接收器类:

public class ConnectionReceiver extends BroadcastReceiver {
 @Override
 public void onReceive(Context context, Intent intent) {
  Log.d("API123", "" + intent.getAction());
  Toast.makeText(context, "isatRunningonbootanyproblem", Toast.LENGTH_SHORT).show();
  context.startService(newIntent(context, MyBackgroundService.class));
 }
}
Run Code Online (Sandbox Code Playgroud)

一旦启动完成,我需要启动我的服务。请建议我该怎么做

下面是我得到的错误日志

 018-11-06 05:25:34.994 885-3000/? W/BroadcastQueue: Background execution not allowed: receiving Intent { act=oneplus.intent.action.ANY_DATA_STATE flg=0x10 } to test.myapplication/.MyReceiver
    2018-11-06 05:25:38.241 885-3000/? W/BroadcastQueue: Permission Denial: receiving Intent { act=android.net.conn.DATA_ACTIVITY_CHANGE flg=0x10 …
Run Code Online (Sandbox Code Playgroud)

android

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

Angular 5 - ngSwitch &amp; ngSwitchCase 不在 html 的真实元素上

我正在尝试根据组件字段类型属性创建不同的 html 表内容。我担心的是,当我在操作 html 表时,我无法在我的 tbody 中插入任何额外的 div,因此使用 ng-template 来覆盖这种情况,但我收到了这个异常“没有 NgSwitch 错误的提供者”。

我需要 ngSwitch & ngSwitchCase 不要在 html 的真实元素上。

这是我的场景stackblitz url

请建议在这里做什么。

ng-switch angular

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