标签: angular6

Angular 6 - 使用 http.get responseType 时出错:ResponseContentType.Blob

我想在(角度 5)中制作一个这样的可观察对象。如何responseType在 Angular 6 中声明?

Angular 5 代码:

public ExportSomeThing(
        ano: number
    ): Observable<IDownloadArquivo> {
        let q = this.http
            .get(this.apiUrl + ano + '/pordia/excel', {
                responseType: ResponseContentType.Blob  // <<<-- This code
            }).map((res) => { 
Run Code Online (Sandbox Code Playgroud)

我的角度 6 代码:

public MyExport(
    ano: number
  ): Observable<IXpto> {
    let q = this.http
      .get( this.api_rul + ano + '/some_path/', {
        responseType: "ResponseContentType.Blob"  // <<<--- error here !!!
      }).map((res) => {
Run Code Online (Sandbox Code Playgroud)

错误是:

[ts]
Argument of type '{ responseType: "ResponseContentType.Blob"; }' is not assignable to …
Run Code Online (Sandbox Code Playgroud)

response httpclient angular angular5 angular6

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

Angular6 - 使用 ngx-translate 使用 API 调用加载翻译到后端

我想在我的前端使用 ngx-translate 在应用程序加载时动态加载翻译。

我的后端以 JSON 格式返回响应,例如:

{
   "something: "something"
}
Run Code Online (Sandbox Code Playgroud)

我想在我的 TranslateLoader 上使用该输出而不是本地en.json文件。

有什么方法可以实现吗?

TL;DL:我想调用“ http://localhost:xxxx/api/translation/EN ”来获取翻译的 JSON 响应并将其加载TranslateHttpLoader

frontend typescript ngx-translate angular angular6

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

在 Angular 6 库中使用 NgRx(带有 ngrx-actions 库)

我正在尝试将具有多个模块的 Angular 应用程序拆分为多个(单独的)Angular 库(使用本指南),因此我可以在多个 Angular 应用程序中使用这些库。
目前该项目有几个模块,例如:

  • 一个用于认证/授权;
  • 一个包含所有类型的表格组件
  • 一个包含所有类型的过滤器组件
  • 一个包含所有类型的图表组件
  • ......(我想你明白了)......

我开始致力于将身份验证/授权模块“转换”为库,因为我预计这将是最难和最复杂的模块。
现在我面临一些问题,我将在下面解释。

该模块(目前存在)结合使用 NgRx 和 ngrx-actions 来减少样板。就像(在指南中)提到的那样,创建了一个库和一个用于测试库的应用程序。我将现有模块的所有内容复制到库文件夹中。

必须进行一些调整,因为现有模块从 environment.ts 和 global.ts 读取一些常量,当它用作库时(可能)不存在。

现在我的文件夹结构如下所示,以提供更多上下文(删除了 node_modules):

.
??? README.md
??? angular.json
??? e2e
?   ??? protractor.conf.js
?   ??? src
?   ?   ??? app.e2e-spec.ts
?   ?   ??? app.po.ts
?   ??? tsconfig.e2e.json
??? package-lock.json
??? package.json
??? projects
?   ??? auth-lib
?   ?   ??? karma.conf.js
?   ?   ??? ng-package.json
?   ?   ??? ng-package.prod.json
?   ?   ??? package-lock.json
? …
Run Code Online (Sandbox Code Playgroud)

ngrx angular angular-library angular6

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

一旦文本框变脏并处于焦点位置,如何显示 mat-error ?

我想在用户开始在输入元素上写东西后显示 mat-error 。以下是我的代码:

<mat-form-field appearance="outline">
    <mat-label>Password</mat-label>
    <input matInput type="password" placeholder="Password" required [(ngModel)]='model.password' #password='ngModel' name='Password' [minlength]='requiredLength' [pattern]="passwordPattern">
    <mat-error *ngIf="password.errors?.pattern">
        Password must be 8 characters long, one numeric, one special character....
    </mat-error>
</mat-form-field>
Run Code Online (Sandbox Code Playgroud)

一旦用户开始输入,我想显示错误消息。目前错误显示在文本框失去焦点上。我也尝试过以下方式:

<mat-error *ngIf="password.dirty">
    <mat-error *ngIf="password.errors?.pattern">
        Password must be 8 characters long, one numeric, one special character....
    </mat-error>
</mat-error>
Run Code Online (Sandbox Code Playgroud)

但这也会产生与以前相同的行为。一种可能的解决方法可能是使用 mat-h​​int。但我不想根据要求将其显示为提示,我需要将其显示为错误。

顺便说一下,我正在使用 ng-form。

是否可以通过在 ng-form 上使用 mat-error 来获得指定的行为?或者我需要为 mat-h​​int 自定义 css 以使其看起来像错误消息?

angular-material angular-material2 angular6

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

“Microsoft.AspNetCore.SpaServices”命名空间中不存在“AngularCli”

我想使用 Microsoft.AspNetCore.SpaServices.AngularCli 但得到这样的错误(“Microsoft.AspNetCore.SpaServices”命名空间中不存在“AngularCli”)。我用命令 dotnet add package Microsoft.AspNetCore.SpaServices --version 2.0.1 添加了 packege,但我仍然有 SpaServices 的问题

asp.net-core-2.0 angular6

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

如何在 Ionic 4 更改时添加标签动画?

我想在选项卡开关上添加向前和向后导航动画。

我想复制 Facebook 应用标签导航动画的当前状态。

我目前尝试在单个选项卡上添加一个方法来调用一个调用向前导航的函数。

<ion-tab-bar slot="bottom">
  <ion-tab-button (click)="goToListTab()" mode="md">
    <ion-icon name="list"></ion-icon>
    <ion-label>Orders</ion-label>
  </ion-tab-button>

  <ion-tab-button (click)="goToNewTab()" mode="md">
    <ion-icon name="add"></ion-icon>
    <ion-label>New Order</ion-label>
  </ion-tab-button>

  <ion-tab-button (click)="goToAccountTab()" mode="md">
    <ion-icon name="person"></ion-icon>
    <ion-label>Account</ion-label>
  </ion-tab-button>
</ion-tab-bar>
Run Code Online (Sandbox Code Playgroud)

我的 .ts 文件具有调用导航的功能。我只包括了一个来简化。

goToAccountTab() {
    this.router.navigateBack('/tabs/account');
}
Run Code Online (Sandbox Code Playgroud)

在 goToAccountTab 上,我希望它可以导航到带有 navigateBack 动画的帐户选项卡,但它成功转到了帐户选项卡,但不执行 navigateBack 动画。

typescript ionic-framework angular ionic4 angular6

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

不同状态的文本颜色 Angular 6

我对 angular 有这样的看法:

在此处输入图片说明

这是我的dashboard.component.ts:

 export class DashboardComponent implements OnInit {
 tablePresetColumns;
 tablePresetData;
 ngOnInit() {
   this.tablePresetColumns = [{id: 1,content: 'Username'},{id: 2,content: 'Status'}];
   this.tablePresetData = [[{id: 1,content: 'john.doe@random.com'},{id: 2,content: 'Busy'}],[{id: 1,content: 'test2@random.com'},{id: 2,content: 'overload'}]];
  }
 } 
Run Code Online (Sandbox Code Playgroud)

这就是我在dashboard.component 上调用表格的方式:

<div eds-tile class="xl-4" style="height: 700px">
    <eds-tile-title>User on Shift</eds-tile-title>  
    <eds-table [columns]="tablePresetColumns" [data]="tablePresetData" [modes]="['compact', 'dashed']"></eds-table>
</div>
Run Code Online (Sandbox Code Playgroud)

eds-表:

selector: 'eds-table',
template: "<table class=\"table\" [ngClass]=\"modes\">\n  <thead *ngIf=\"columns\">\n    <tr>\n      <th *ngFor=\"let col of columns\">\n        {{col.content}}\n      </th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr *ngFor=\"let row of data\">\n      <td *ngFor=\"let cell of row\">\n …
Run Code Online (Sandbox Code Playgroud)

html css less angular angular6

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

在父组件中的值更改时更新子组件中的值

我在 Angular 工作,在那里 -

  • 我正在尝试根据父组件中的值更改更新子组件中的值

    (因为值是从其他组件动态传到父组件的)。

我是如何尝试的

  • 我尝试使用 @Input 装饰器将数据从父组件传递到子组件

  • 使用 @Input 值仅在组件加载时传递一次,而后者不传递值

我在下面分享我的代码

父组件

.html

<app-banner [tournamentType]='tournamentType'></app-banner>
Run Code Online (Sandbox Code Playgroud)

.ts

子组件

.ts 文件

import { Component, OnInit , Input } from '@angular/core';
import { ServicesService } from '../service/services.service';

@Component({
  selector: 'app-banner',
  templateUrl: './banner.component.html',
  styleUrls: ['./banner.component.scss']
})
export class BannerComponent implements OnInit {

  @Input() tournamentType;

  sportsType : any = 1;



  constructor(private rest : ServicesService) { }

  ngOnInit() {
    console.log("this. is banner page" + this.tournamentType);
    alert('hello');

    this.loadDataFromApi(1);
  }

  loadDataFromApi(sportsType) {

     this.rest.getbanner(this.sportsType).then(res => …
Run Code Online (Sandbox Code Playgroud)

angular angular5 angular6

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

Angular 6 应用程序在 safari 浏览器中不起作用

Angular 应用程序在 IE 和 chrome 中运行良好,但在 safari 中它甚至没有显示任何错误也无法正常工作并尝试使用 polyfill

在这里 polyfill.ts

/** IE9, IE10 and IE11 requires all of the following polyfills. **/
import 'core-js/es6/symbol';
 import 'core-js/es6/object';
 import 'core-js/es6/function';
 import 'core-js/es6/parse-int';
 import 'core-js/es6/parse-float';
 import 'core-js/es6/number';
 import 'core-js/es6/math';
 import 'core-js/es6/string';
 import 'core-js/es6/date';
 import 'core-js/es6/array';
 import 'core-js/es6/regexp';
 import 'core-js/es6/map';
  import 'core-js/es6/weak-map';
 import 'core-js/es6/set';
import 'core-js/client/shim';
import 'intl';
import 'intl/locale-data/jsonp/en';

/** IE10 and IE11 requires the following for NgClass support on SVG elements */
 import 'classlist.js';  // Run `npm install --save classlist.js`.

/** …
Run Code Online (Sandbox Code Playgroud)

safari mobile-safari polyfills progressive-web-apps angular6

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

更改突出显示日期的背景后如何刷新 mat-calendar

我有一个永远打开的 mat-calendar 控件。在初始加载时,我会突出显示一组日期,这些日期可以执行以下操作:突出显示 mat-calendar 中的某些日期。现在我必须通过单击按钮突出显示今天(或选定的日期)。只有当我更改为不同的月份,然后返回到当前月份的视图时,突出显示才有效。有没有办法动态刷新 mat-calendar?请指教。

https://am-all-imports-zwnjbd.stackblitz.io

css angular angular6 angular-material-7

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