标签: angular6

如何更改角形材料中的垫形场边界颜色

我正在尝试以有角度的材料更改文本框的边框颜色。现在有3种不同的颜色(悬停,聚焦,空闲)。如何更改这些颜色?我希望它们与我的主题不同。

<mat-form-field id="test" appearance="outline">
  <mat-label class="test2">Outline form field</mat-label>
  <input matInput placeholder="name">
</mat-form-field>
Run Code Online (Sandbox Code Playgroud)

有一些选项可以更改字体大小,但是我似乎无法弄清楚颜色:

mat-form-field.mat-form-field {
    font-size: 16px;
    color: red;
}
Run Code Online (Sandbox Code Playgroud)

此处的color属性不变。

感谢您抽出宝贵的时间。

angular-material angular angular6

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

Angular 6:HttpClient获取JSON文件404错误

使用HTTP客户端,我将检索一个JSON文件,该文件位于assets使用CLI生成的Angular 6 App中的目录中。虽然我知道有几个与此主题相关的问题(和答案),但是在我的情况下没有一个有效。

下面是我的文件结构:

在此处输入图片说明

具体来说,我正在尝试检索 us-all-all.geo.json

angular.json

 "projects": {
    "ng-ngrx-highcharts-example": {
      "root": "",
      "sourceRoot": "src",
      "projectType": "application",
      "prefix": "app",
      "schematics": {},
      "architect": {
        "build": {
          "builder": "@angular-devkit/build-angular:browser",
          "options": {
            "outputPath": "dist/ng-ngrx-highcharts-example",
            "index": "src/index.html",
            "main": "src/main.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "src/tsconfig.app.json",
            "assets": [
              "src",
              "src/assets",
              "src/favicon.ico",
              "src/assets/us-all-all.geo.json"
            ],
            "styles": [
              "src/styles.css"
            ],
            "scripts": []
          },
Run Code Online (Sandbox Code Playgroud)

map-data.service.ts

import { Injectable } from '@angular/core';
import { Observable, of, from } from 'rxjs';
import * as $ from 'jquery';
import { …
Run Code Online (Sandbox Code Playgroud)

angular angular-httpclient angular6

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

查找Array Angular和Typescript中的最小和最大元素

大家好,我有阵列,我需要执行各种操作,如总和,平均值.所有这三个都实现了,现在我需要找到数组中的最小值和最大值.我坚持下面是代码.

以下是TS部分

people: Array<number> = [1, 2, 3, 4, 5];
  total: number = 0;
  arrayLength: number = this.people.length;
  average: number = 0;

  sum() {
    for (var i in this.people) { this.total += this.people[i]; }
  }

  ngOnInit() {
    this.sum();
    this.average = (this.total / this.arrayLength);
  }
Run Code Online (Sandbox Code Playgroud)

下面是HTML部分

<span *ngFor="let p of people" style="font-size:18px">{{p}} </span><br><br>
<button >Quantity</button> = {{arrayLength}}<Br><br>
<button >Average</button> = {{average}}<Br><br>
<button >Sum</button> <span *ngIf="sumShow"> = {{total}}</span><Br><br>
Run Code Online (Sandbox Code Playgroud)

arrays typescript angular angular6

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

单击图标/按钮时如何从表格中删除一行

我在项目中使用带有分页组件的Table。单击删除图标时需要一次删除单行。这是我创建的stackblitz链接。

尝试过此链接,他们在这里执行了编辑| 更新| 删除操作。我只希望删除操作。如何实现?

angular-material angular angular6

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

Http Interceptor无法工作在角度6

我已经使用httpintercept处理我的角度6项目中的数据服务中的401(未授权)错误.但httpintercept服务不接受我的项目.

这是我的intercept.services.ts文件

export class InterceptService  implements HttpInterceptor {

  constructor(private authService: AuthService) { }

  // intercept request and add token
    intercept(request: HttpRequest<any>, next: HttpHandler):Observable<HttpEvent<any>> {

      // modify request
      request = request.clone({
        setHeaders: {
          Authorization: `Bearer ${JSON.parse(localStorage.getItem('currentUser')).token}`
        }
      });

       console.log("----request----");

     console.log(request);

     console.log("--- end of request---");


      return next.handle(request)
      .pipe(
          tap(event => {
            if (event instanceof HttpResponse) {

              console.log(" all looks good");
              // http response status code
              console.log(event.status);
            }
          }, error => {
           // http response status code
              console.log("----response----");
              console.error("status code:");
              console.error(error.status);
              console.error(error.message);
              console.log("--- …
Run Code Online (Sandbox Code Playgroud)

angular angular6

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

如何将params(action.payload)传递给ngrx/effects中的服务?

我是ngrx-6的新手.效果将侦听操作"LOAD_COURSE_DETAILS",并应使用course_id(action.payload)调用服务.但我收到一个错误

"行动"类型中缺少"toFixed"属性.

但是,如果我执行console.log,我可以看到数据从组件传递到效果.

将params添加到效果中

如何将参数传递给服务?

提前致谢.


文件:效果

@Effect()
loadCourseDetails$ = this.actions$.pipe(
  ofType(CourseActionTypes.LOAD_COURSE_DETAILS),
  switchMap((action) => {
    console.log('in course effects', action);
    return this.courseService.getCourseDetails(action).pipe(
      map((data) => new fromCourse.LoadCourseDetailsSuccess(data))
    );
  })
);
Run Code Online (Sandbox Code Playgroud)

file:actions.ts(我的操作定义了有效负载)

export class LoadCourseDetails implements Action {
  readonly type = CourseActionTypes.LOAD_COURSE_DETAILS;
  constructor(public payload: Number) {}
}
export class LoadCourseDetailsSuccess implements Action {
  readonly type = CourseActionTypes.LOAD_COURSE_DETAILS_SUCCESS;
  constructor(public payload: ICourse) {}
}
Run Code Online (Sandbox Code Playgroud)

file:component.ts(dispatch action)

loadCourseDetails(id: Number) {
  console.log('dispatch course id', id);
  this.store.dispatch(new fromCourse.LoadCourseDetails(id));
}
Run Code Online (Sandbox Code Playgroud)

file:service.ts(由效果调用)

getCourseDetails(courseId: Number) {
    return this.http.get(`url/${courseId}.json`);
}
Run Code Online (Sandbox Code Playgroud)

ngrx ngrx-effects angular6

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

Mat输入到值属性的两种方式绑定不起作用

我已经创建了Mat Input控件,并将它的value属性与控制器上的属性进行了2种方式的绑定,但是当我输入输入时,绑定属性不会更新。

堆栈闪电战链接:https : //stackblitz.com/edit/angular-7ojsjo

<div class="example-container">
  <mat-form-field>
    <input matInput placeholder="Input" [(value)]="currentValue">
  </mat-form-field>

  <h1>{{currentValue}}</h1>
</div>
Run Code Online (Sandbox Code Playgroud)

为什么绑定的属性不更新?

angular angular6

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

在Angular 6中折叠/展开嵌套div

我正在使用div制定类似于结构的时间表。我的设计看起来像这样。在此处输入图片说明

我想要的是在加载时,仅应显示1级(所有场所),并且在单击场所时应显示其直接子级,依此类推。有没有办法做到这一点。我的html是:

<div class="div-table">
    <div class="div-table-row">
        <div class="div-header-col" style="visibility: hidden;">A</div>
        <div *ngFor="let date of dates" class="div-date-col">{{date | date:'d E'}}</div>
    </div>


    <!-- level1 -->
    <div *ngFor="let venue of venues" class="level1" style="color: red">
        <div class="div-table-row-level1" >
            <div class="div-header-col">{{venue.name}}</div>
            <div *ngFor="let x of dates" class="div-event-level1-col"></div>
        </div>

        <!-- level2 -->
        <div *ngFor="let category of venue.categories" class="level2" style="color: blue">
            <div class="div-table-row-level2">
                <div class="div-header-col" style="padding-left: 10px">{{category.name}}</div>
                <div *ngFor="let x of dates" class="div-event-level2-col"></div>
            </div>

            <!-- level3 -->
            <div *ngFor="let asset of category.assets" class="level3" style="color: green">
                <div class="div-table-row-level3"> …
Run Code Online (Sandbox Code Playgroud)

html ngfor angular angular6

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

使用角度枚举选择下拉菜单项

我想实现选择菜单,该菜单使用枚举数据根据所选的字符串显示数据和保存的数字:

HTML代码:

<div class="form-group state_raw">
    <label for="state_raw">State</label>
    <select class="custom-select" name="state_raw" [(ngModel)]="merchant.state_raw" id="state_raw" required>
      <option selected></option>
      <option [value]="type" *ngFor="let type of types">{{type | formatType}}</option>
    </select>
  </div>
Run Code Online (Sandbox Code Playgroud)

显示数据和转换后的数字值的枚举:

export enum MerchantStatusType {
  'Being set up' = 1,
  'Live for processing' = 2,
  'Trading suspended' = 3,
  'Account suspended' = 4
}
Run Code Online (Sandbox Code Playgroud)

选择菜单的对象:

export class MerchantNew {
  constructor(
    public name: string,
    public address_state: string,
  ) {}
}
Run Code Online (Sandbox Code Playgroud)

如何实现呢?我想显示字符串,但是将数字保存到数据库中?

编辑:我尝试过此:

枚举:

export enum MerchantStateType {
  being_set_up = 1,
  live_for_processing = 2,
  trading_suspended = 3, …
Run Code Online (Sandbox Code Playgroud)

typescript angular angular6

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

角度6中的搜索过滤器

我有两个组件,分别称为list和details,单击list-item列表中的特定组件。它将发出选定/单击list-item的details组件,如下图所示。

在此处输入图片说明

现在,我在该组件search上方放置了另一个组件,list如下所示:

在此处输入图片说明

如何为列表组件中的当前内容应用过滤器?这样我就可以轻松搜索。list-itemslist-items

Stackblitz链接

typescript angular angular6

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