标签: angular6

将参数从组件发送到 angular 6 中的服务构造函数

我是 angular6 的新手,当我将参数从组件发送到服务时,我收到 StaticInjectorError。怎么了?

我的代码是这样的组件:

import { Component, Input, OnInit } from '@angular/core';
import { myService } from '../../@core/data/myService';
@Component({
  selector: 'table',
  templateUrl: './table.component.html'
})
export class TableComponent implements OnInit {
  constructor(private service: myService) {
  }
  ngOnInit() {
    this.service = new myService ("name");
}
Run Code Online (Sandbox Code Playgroud)

服务:

 import { Injectable, Inject } from '@angular/core';
    import { Observable } from 'rxjs/Observable';
    import { DataService } from './data.service';

    @Injectable() export class myService {

        constructor(
            entityName: string,
        ) {
            console.log(entityName);
        }
    }
Run Code Online (Sandbox Code Playgroud)

app.module.ts:

import { …
Run Code Online (Sandbox Code Playgroud)

frontend dependency-injection web-frontend typescript angular6

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

如何在 Angular 6 中创建级联下拉列表(国家和州列表)

如何在 Angular 6 中创建级联下拉列表(国家和州列表)。我想要一个完整的国家/地区和 Angular 6 中的州列表。

任何知道请分享您的想法的人。

country-codes cascading dropdown angular angular6

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

Angular 6 - 期望验证器在异步验证器中返回 Promise 或 Observable

在我的 Angular 6 应用程序中,我有一个异步验证器来检查输入的电子邮件是否已经注册,但现在我得到“预期验证器返回 Promise 或 Observable”,我真的不知道为什么。

import { UserService } from '../user/service/user.service';
import { AbstractControl, ValidationErrors, AsyncValidator } from '@angular/forms';
import * as validationUtils from '../validation/validation-utils';
import { Injectable } from '@angular/core';
import { of, Observable } from 'rxjs';
import { map } from 'rxjs/operators';

@Injectable({
  providedIn: 'root'
})
export class EmailExistValidator implements AsyncValidator {
  constructor(private userService: UserService) {
  }

  validate(emailControl: AbstractControl): Promise<ValidationErrors | null> | Observable<ValidationErrors | null> {
    const email = emailControl.value;

    if (new RegExp(validationUtils.emailRegex).test(email)) {
      this.userService …
Run Code Online (Sandbox Code Playgroud)

angular angular6

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

Angular 6 中 ngIf 中的多个条件

我想隐藏一个 div 并想显示另一个我在代码下面写的

我的代码

我的问题是我在 ngIf 中使用了多个条件但无法正常工作。单击“显示子内容 1”后,我想隐藏主要内容并希望显示所有按钮的“子内容 1”,反之亦然。我该怎么做。请帮忙。

typescript angular-ng-if angular angular5 angular6

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

如何在 Angular 中使用 plyr npm 模块在 Angular2 中创建视频播放器?

我正在尝试使用这个 (Plyr- https://www.npmjs.com/package/plyr ) npm 包来创建一个可以流式传输 m3u8 和 Youtube 视频的视频播放器,他们的 npm 页面有两个演示,但他们在普通的javacript。

谁能解释如何在 angular 6 应用程序中使用它?Hls怎么用等等

特别是这两个例子:https : //codepen.io/pen?template=oyLKQb#enter code here

https://codepen.io/pen?template=GGqbbJenter code here

typescript angular angular6 plyr.js

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

如何在角度 6 中更改拦截器中的内容类型?

有些服务需要令牌,有些服务需要不同的内容类型。我应该如何在拦截器文件中管理它们?

angular-http-interceptors angular6

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

在 BehaviorSubject 值 === false 时延迟可观察流

我有一个每 2 秒执行一次 HTTP 请求并更新视图的应用程序。问题是,我必须做一些用户触发的 CSS 动画,这些动画大约需要一秒钟并且经常被破坏,因为 Angular 在动画运行时更新 DOM。

我使用Akita商店并像这样检索 observables:

this.dosingVessels$ = this.dosingVesselsQuery.selectAll().pipe(*needs rxjs operator magic*);
Run Code Online (Sandbox Code Playgroud)

然后像这样在组件中显示它们:

    <app-solving-vessel *ngFor="let vessel of solvingVessels$ | async"
                    [vessel]="vessel"
                    [ngClass]="{'animation-class': hoverId === vessel.id}">
    </app-solving-vessel>
Run Code Online (Sandbox Code Playgroud)

在动画进行时我怎么能做到这一点:

animate(event, vessel) {
    this.updateView.next(false); // prevent from updating
    this.hoverId = vessel.id; // triggers animation
    timer(1000).subscribe(tick => this.updateView.next(true)); // allow normal updating
}
Run Code Online (Sandbox Code Playgroud)

视图没有更新。

我发现了 delayWhen 运算符,但所有示例都带有计时器,我不确定这是否是正确的方法。

rxjs angular angular6 akita angular-akita

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

Rxjs 将 Json 文档中的数组映射到新的数组类型

我正在 Angular 服务中从 PouchDB 检索文档。以下列格式检索文档:

{
"_id":"segments",
"_rev":"1-4f0ed65cde23fe724db13bea1ae3bb13",
"segments":[
    { "name":"Aerospace" },
    { "name":"Auto repair" },
    { "name":"Commercial" },
    { "name":"Education" },
    { "name":"Energy" },
    { "name":"Farm/ranch" },
    { "name":"Furniture" },
    { "name":"Heavy Equipment" },
    { "name":"Hobbyist" },
    { "name":"Infrastructure" },
    { "name":"Luxury/Leisure" },
    { "name":"Military" },
    { "name":"MUP" },
    { "name":"Processing" },
    { "name":"Rail" },
    { "name":"Transportation" }
]}
Run Code Online (Sandbox Code Playgroud)

我想将它映射到一个新的数组,看起来像:

[
  { value: "Aerospace", viewValue: "Aerospace" },
  { value: "Auto Repair", viewValue: "Auto Repair" },
  { value: "Commercial", viewValue: …
Run Code Online (Sandbox Code Playgroud)

javascript mapping angular6 rxjs6

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

无法使用我的 css 属性覆盖有角度的材质主题

我使用Angular 6.0.8同Angular Material theme版本6.4.0

每当我尝试稍微修改材质主题时,它永远不会起作用,因为我总是发现材质主题属性会覆盖我的 CSS 属性,如下所示:

currentColor   .mat-input-element (material theme)
initial        input, textarea, select, button (user agent stylesheet)
#1072BA        .English
#1072BA        .English
#1072BA        body
Run Code Online (Sandbox Code Playgroud)

仅应用第一个属性(其余的被删除)

我尝试了多种变体来解决这个问题,但没有一个奏效(比如使用重要的或改变导入主题的顺序)

那么在 Material 主题和用户样式表中更改小东西的正确方法是什么?(例如,应用此英语规则)

我的styles.scss如下,它运行良好,只有覆盖颜色和字体等材质主题不起作用:

@import '~@angular/material/prebuilt-themes/indigo-pink.css';

/* You can add global styles to this file, and also import other style files */

/* prevent clicking in the wizard nav header */
.mat-horizontal-stepper-header{
  pointer-events: none !important;
}

@font-face {
  font-family: 'Material Icons';
  font-style: normal;
  font-weight: 400;
  src: url(./assets/material_icons/material_icons.woff2) …
Run Code Online (Sandbox Code Playgroud)

css angular-material2 angular angular6 angular-material-6

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

如何在 ANGULAR 6 的多级延迟加载中设置路由器

我是 Angular 的新手,正在编写我的第一个Angular应用程序。我希望这个“应用程序”具有三种布局:Public、Mumber 和 Admin。我创建了这样的项目:

|-src
|-app
    |-public(module)
        |-home(module)
            |-pages(foler)
                |-index(component folder)
                    |-index.component.ts(like a controler include the selector of article-list component and product-list component, inject article service and product service)
            |-components
                |-article-list(component folder)
                    |-article-list.component.css
                    |-article-list.component.html
                    |-article-list.component.ts
                |-product-list(component folder)
                    |-product-list.component.css
                    |-product-list.component.html
                    |-product-list.component.ts
            |-home-routing.module.ts
            |-home.component.ts
            |-home.module.ts
        |-article(module)
            |-pages(folder)
                |-index(component folder)
                    |-index.component.ts(like a controler include the selector of article-list component, inject article service)
                |-list-by-category(component folder)
                    |-list-by-category.component.ts(like a controler loop category and include the selector of article-list component, inject article service)
                |-detail(component …
Run Code Online (Sandbox Code Playgroud)

angular6

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