标签: angular5

Angular 5 中的 Karma 测试失败:Http 失败响应

应用程序组件:

ngOninit(){
    this.http.get('../assets/data/dummy.json').subscribe(result => {
      this.favorites = result;
    });
}
Run Code Online (Sandbox Code Playgroud)

测试名称:AppComponent 应在 h1 标记中呈现标题

Karma 消息:失败:http://localhost:9876/assets/data/dummy.json的 Http 失败响应:404 Not Found

如果我在 get 方法中将 json 的绝对路径设置为http://localhost:4200/assets/data/dummy.json,则错误消失

unit-testing karma-jasmine angular5

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

Bootstrap 模态窗口不会在角度 5 的路线更改时关闭

在我的 Angular 5 应用程序中使用 "@ng-bootstrap/ng-bootstrap": "1.0.0-beta.6" 版本时,一切看起来都很好。但是,如果我在模态窗口中有一个触发路线更改的按钮,则即使在路线更改之后,模态窗口也不会关闭。

在很少的研究中,我发现了类似的东西,在以前的引导程序版本中,点击模态窗口,我们用来查看特定组件内与模态窗口相关的代码,以及随着组件被销毁,甚至模态窗口被销毁时的路由更改。但是在当前版本中,我几乎在 body 标记的末尾看到了与模态窗口相关的代码,这些代码不受路由更改的影响。

无论如何要在路线更改时关闭模态?

bootstrap-modal ng-bootstrap angular5

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

表示 res.status(200).json(...) 仅发送 json 消息。如何检索状态码?

在我的数据库中成功创建新项目后,我发送:

res.status(201).json({message:"Successfully Registered"});
Run Code Online (Sandbox Code Playgroud)

在我的有角度的前端,我能够console.log(res)并接收:

{message: "Successfully Registered"}

1)如何获取前端的状态码?res.status返回未定义。我得到的唯一响应是 JSON。

2) 确认所需 api 调用成功的最佳方法是什么?例如,当我登录并且凭据正确时,我应该检查 a200然后继续吗?或者发送自定义 JSON 消息并检查该消息是否显示“成功登录”,然后继续?

json http-status-code-301 express angular5

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

基于 Angular 5 角色的路由

我有一个网站,其主页在我的路由模块中定义为:

const appRoutes: Routes = [
{
  path: '',
  component: HomeComponent
}];
Run Code Online (Sandbox Code Playgroud)

现在我想为管理员用户显示一个不同的主页(仪表板页面)。我可以更改根据用户角色调用的“组件”吗?

在伪代码中类似:

const appRoutes: Routes = [
{
  path: '',
  IF UserRole = 'Admin'
     component: DashboardComponent
  ELSE
     component: HomeComponent
}];
Run Code Online (Sandbox Code Playgroud)

angular5

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

chartjs-plugin-annotations 未以角度 5 显示

使用 chart.js 和插件 chartjs-plugin-annotation 时,使用 angular 5 时不会显示注释,也不会显示错误消息。

我创建了一个展示问题的简化代码示例

console.log(Chart.plugins) 显示插件看起来注册为 plugin[3] 但是它没有内置的 id,这是一个问题吗?

图片

图表组件.ts

import { Component, Inject } from '@angular/core';
import { Chart } from 'chart.js';
import 'chartjs-plugin-annotation';

@Component({
  selector: 'app-chart-component',
  templateUrl: './chart.component.html'
})
export class ChartComponent {
  public currentCount = 0;

  chart : Chart ; // This will hold our chart info

  simpleChart() {

    console.log(Chart.plugins);

    this.chart = new Chart('canvas', {
      type: 'line',
      data: {
        labels: ['0','1','2', '3','4'],
        datasets: [
          {
            data: [0,1,2,5,4,5],
            borderColor: "#3cba9f",
            fill: false,
          }, …
Run Code Online (Sandbox Code Playgroud)

chart.js angular5

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

如何实现全选角材料下拉angular 5

我正在使用 mat-select 来显示下拉菜单,我需要在 angular 下拉菜单中选择所有功能。

下面是我的html

<mat-select formControlName="myControl" multiple (ngModelChange)="resetSelect($event, 'myControl')">
    <mat-option>Select All</mat-option>
    <mat-option [value]="1">Option 1</mat-option>
    <mat-option [value]="2">Option 2</mat-option>
    <mat-option [value]="3">Option 3</mat-option>
</mat-select>
Run Code Online (Sandbox Code Playgroud)

这是我的 ts 代码

/**
 * click handler that resets a multiple select
 * @param {Array} $event current value of the field
 * @param {string} field name of the formControl in the formGroup
 */
protected resetSelect($event: string[], field: string) {
    // when resetting the value, this method gets called again, so stop recursion if we have no values …
Run Code Online (Sandbox Code Playgroud)

typescript angular-material angular angular5

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

角度表单控件不更新 UI 仅更新值

我有一个这样的表格:

this.filterFormGroup= this.formBuilder.group({
      gmt_scope: [''],
      priority: [''],
      region: [''],
      category: [''],
      status: [''],
      original_deadline: [''],
      responsibles: [''],
      pms: [''],
      updated_at: ['']
    });
Run Code Online (Sandbox Code Playgroud)

表单通过 API 填充:

<form [formGroup]="filterFormGroup" >
          <div fxLayout="row" fxLayoutWrap="wrap" fxLayout="center center"  class="row">
            <div fxFlex.gt-sm="20" fxFlex="100" class="p-10" fxLayoutAlign="center center">
              <!-- <mat-slide-toggle color="primary" stepper="0" formControlName="gmt_scope">GMT SCOPE</mat-slide-toggle> -->
              <mat-form-field>
                <mat-select  placeholder="GMT Scope" stepper="0" formControlName="gmt_scope" >
                  <mat-option *ngFor="let gmt_scope of gmt_scopes" [value]="gmt_scope.value" >
                    {{ gmt_scope.viewValue }}
                  </mat-option>
                </mat-select>
              </mat-form-field>
            </div>
            <div fxFlex.gt-sm="20" fxFlex="100" class="p-10" fxLayoutAlign="start center">
              <mat-form-field>
                <mat-select placeholder="Priority" stepper="0" formControlName="priority">
                  <mat-option …
Run Code Online (Sandbox Code Playgroud)

angular angular-forms angular5

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

打字稿:无法将默认参数值设置为 false

我有一个方法,它有一些可选参数,像这样,

initializeInteraction(opts: { type?: string; freehand?:boolean= false }) {
    this._draw = this.drawService.initDraw({ drawtype: opts.type });
    this._drawInteraction = this._draw.interaction;
    this.mapService.addVector(this._draw.vector);
    this.mapService.addInteraction(this._drawInteraction);
  } 
Run Code Online (Sandbox Code Playgroud)

我想仅在需要时将 的值设置freehandtrue,否则我希望将其设置为false

但是当我宣布这一点时

initializeInteraction(opts: { type: string; freehand?:boolean= false }) {}
Run Code Online (Sandbox Code Playgroud)

我收到一个错误

[ts] A type literal property cannot have an initializer. [1247]
Run Code Online (Sandbox Code Playgroud)

typescript angular angular5

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

如何从角度为 6 的数组中删除重复的对象

我正在尝试删除数组中的重复值对象但不起作用...我认为重复函数正在运行但未反映在li列表中。你能找出我必须改变的地方吗?

我的服务文件:

 addComp(Names,c){   
 this.item.push({ name: Names, componentid: c});
 this.uniqueArray = this.removeDuplicates(this.item, "name"); //this line issue
 this.item=this.uniqueArray; //this line issue
 }
Run Code Online (Sandbox Code Playgroud)

typescript angular2-services angular angular5 angular6

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

在angular5 / 6中单击按钮时如何从url下载文件

我有一个网址,例如:abc.net/files/test.ino 要求是通过角度为 5 或 6 的按钮单击事件下载 .INO 文件

angular angular5 angular6

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