标签: angular8

Request.Form.Files' 在 asp.net core 2.2 中引发了类型为 'system.invalidoperationexception' 的异常,内容类型为 'application-json' 不正确

我正在使用带有 Angular 8 的 asp.net core 2.2。我正在尝试上传文件,其中包含一些要使用 post 方法保存的数据。数据正在传递到控制器,但在控制器中 Request.Form 对象抛出错误。

它在带有 Angular 2 的 asp.core 2.0 中正常工作。但我正在尝试使用 asp.net core 2.2 将此项目更新为 Angular 8。现在我收到此错误“Request.form.files”引发了“system.invalidoperationexception”类型的异常。

角度服务代码:

        saveNewMail(user: CommunicationActivityModel, files: File[]) {
        let body = JSON.stringify(user);
        let formData = new FormData();
        for (var i = 0; i < files.length; i++) {
          formData.append('uploadedFiles', files[i]);
        }
         formData.append('user', body);

         let requestedUrl = this.baseUrl + 'SaveNewMail';

         return this.apiService.postFormData(requestedUrl, 
         formData).pipe(map(response => response));

   }
Run Code Online (Sandbox Code Playgroud)

api.service代码:

 postFormData(path: string, body: FormData): Observable<any> {
    return this.http.post(
      `${environment.api_url}${path}`,
       body
     ).pipe(catchError(this.formatErrors));
  }
Run Code Online (Sandbox Code Playgroud)

控制器代码: …

asp.net-core angular8

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

升级到 Nebular 4 已停止显示很棒的字体图标。设置包也不起作用

Angular 版本 8 升级后,Nebular 更新到版本 4。升级后,我看不到之前显示的很棒的字体图标。

我尝试浏览 nebular 的这份文档,它要求我们将 font Awesome 注册为默认包。但即使这样做也不起作用。 https://akveo.github.io/nebular/docs/guides/register-icon-pack#register-icon-pack

找不到关于此问题的足够讨论。Font Awesome 已包含在内,并且我已将其添加到我的 angular.json 文件中

constructor(private iconService: NbIconLibraries) {
    this.iconService.registerFontPack('font-aweome');
    this.iconService.setDefaultPack('font-aweome');
}
Run Code Online (Sandbox Code Playgroud)

Nebular 应该接受字体很棒的图标。

font-awesome-5 nebular angular8

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

刷新时未获取“路由器事件”

我正在为我的项目做面包屑。我这里有两个问题:

  1. 当我来自其同级页面时,未生成面包屑
  2. 页面刷新时未生成面包屑

两者该如何解决呢?

import { Component, OnInit } from '@angular/core';
import { Router, ActivatedRoute, RoutesRecognized, NavigationStart,  NavigationEnd, Params, PRIMARY_OUTLET } from '@angular/router';
import { filter, map } from 'rxjs/operators';
import { BreadCrumbsService } from './../../services/bread-crumbs.service';


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

    breadcrumbList: Array<any> = [];

    /**
        * Setting Breadcrumb object, where name for display, path for url match,
        link for heref value, getting datas from BreadCrumbsService service
    */

    constructor(private router: Router, …
Run Code Online (Sandbox Code Playgroud)

angular angular-router angular8

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

无法绑定,因为它不是选择器组件的已知属性

我想将变量从一个组件传递到另一个组件,并且我正在使用 @input

这是我的父组件:

@Component({
    selector: 'aze',
    templateUrl: './aze.component.html',
    styleUrls: [('./aze.component.scss')],
    providers: [PaginationConfig],
})

export class azeComponent implements OnInit {
    public hellovariable: number = 100;
}
Run Code Online (Sandbox Code Playgroud)

这是父组件的模板:

<app-my-dialog [hellovariable]="hellovariable"></app-my-dialog>
Run Code Online (Sandbox Code Playgroud)

这是我的子组件:

@Component({
  selector: 'app-my-dialog',
  templateUrl: './my-dialog.component.html',
  styleUrls: ['./my-dialog.component.css']
})

export class MyDialogComponent implements OnInit {
  @Input() hellovariable: number;
  constructor() { }

  ngOnInit() {
    console.log(hellovariable);
  }
Run Code Online (Sandbox Code Playgroud)

这是子模板:

 <h3>Hello I am {{hellovariable}}<h3>
Run Code Online (Sandbox Code Playgroud)

这是app.module.ts:

@Component({
    selector: 'aze',
    templateUrl: './aze.component.html',
    styleUrls: [('./aze.component.scss')],
    providers: [PaginationConfig],
})

export class azeComponent implements OnInit {
    public hellovariable: number = 100; …
Run Code Online (Sandbox Code Playgroud)

javascript typescript angular angular8

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

Angular 8 默认路由

我有一个运行 Angular 8.2 的应用程序。除默认路由外,路由运行良好。

当我去时website.com我想被重定向到website.com/sign-in

应用程序路由模块

const routes: Routes = [
  {
    path: '',
    redirectTo: 'sign-in',
    pathMatch: 'full'
  },
  {
    path: '',
    component: PublicLayoutComponent,
    data: { title: 'Public Views' },
    children: PUBLIC_ROUTES
  },
  {
    path: '',
    component: PrivateLayoutComponent,
    data: { title: 'Private Views' },
    children: PRIVATE_ROUTES
  },
];
Run Code Online (Sandbox Code Playgroud)

公共路由模块

export const PUBLIC_ROUTES: Routes = [
  {
    path: "sign-in",
    loadChildren: () =>
      import('../features/sign-in/sign-in.module').then(
        m => m.SignInModule
      )
  }
];
Run Code Online (Sandbox Code Playgroud)

私有路由模块

export const PRIVATE_ROUTES: Routes = [
  {
    path: …
Run Code Online (Sandbox Code Playgroud)

components routes angular angular8

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

Angular 8 在拦截器中订阅可观察对象

我正在尝试编写一个 HTTP 拦截器来向请求添加“访问级别”参数。我试图从可观察的 currentAccessLevel$ 中获取值。但是,可观察对象未正确返回,并且拦截器破坏了整个请求周期。

这个问题已经在这里这里有了答案,但是,接受的答案似乎在 Angular 8 中不起作用。我不确定我是否做错了什么,或者是否对 Angular 8 中的拦截器进行了某种更改。

我还尝试过使用 switchMap、flatMap 和 mergeMap。

import { Injectable } from '@angular/core';
import {
  HttpRequest,
  HttpHandler,
  HttpEvent,
  HttpInterceptor
} from '@angular/common/http';
import { Observable } from 'rxjs';
import { switchMap } from 'rxjs/operators';
import { AuthService } from 'src/app/services/auth/auth.service';

@Injectable()
export class AccessLevelInterceptor implements HttpInterceptor {
  private accessLevel: string;

  constructor(private authService: AuthService) { }

  // Intercept HTTP Requests
  intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {

    // Get current …
Run Code Online (Sandbox Code Playgroud)

interceptor observable rxjs angular angular8

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

如何将此 javascript 和 HTML 代码添加到 Angular 项目中?我可以从 Angular 中的 javascript 函数渲染 html 吗?

如何将此 javascript 和 HTML 代码添加到 Angular 项目中? 我已将 func.js 放在我的 Angular 项目的 src 文件夹中以及我尝试导入和使用 ngAfterViewInit() 来加载和使用 javascript 函数的 app.component.ts 文件中

这些是我尝试添加到 Angular Web 应用程序中的 javascript 和 html 文件:

函数.js

const uName = 'admin';
const uPass = '12345';
const endpoint = 'http://11.11.111.241:8000';
const resource = {
    questionnaire: 'Questionnaire',
    valueset: 'ValueSet'
}

//get questionnaire
var url = 'http://cihi.ca/fhir/irrs/Questionnaire/abc-abc-community-on';
var quesJson = getData(resource.questionnaire, '?url=' + url);
quesJson = quesJson.entry[0].resource
// saveJsonToFile(quesJson, 'irrsQuesJson');
var copy = $.extend(true, {}, quesJson);
//convert to lhc form
var …
Run Code Online (Sandbox Code Playgroud)

javascript angular-components angular angular7 angular8

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

如何在角度上传递拦截器上的查询?

有什么方法可以在角度8的拦截器上传递查询和参数

    const params = new HttpParams()
            .set('lang', localStorage.getItem('language'))
            .set('android_version', '1')
Run Code Online (Sandbox Code Playgroud)

angular angular8

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

如何在 Angular 8 中的抽象类和抽象类的实现中使用 @Component 装饰器?

我使用 Angular 8 并尝试使用抽象组件。我想在抽象类中定义 templateUrl 和 styleUrls,但在实现的类中定义选择器名称。像这样:

@Component({
  // selector isn't defined here
  templateUrl: './abstract-list.component.html',
  styleUrls: ['./abstract-list.component.scss']
})
export abstract class AbstractListComponent<T> implements OnInit {
  // ...
}
Run Code Online (Sandbox Code Playgroud)

而在幼儿班

@Component({
  selector: 'app-my-custom-list',
  // templateUrl & styleUrls is should be inherited
})
export class MyCustomListComponent extends AbstractListComponent<MyCustomListInterface> implements OnInit {
  // ...
}
Run Code Online (Sandbox Code Playgroud)

我尝试仅在这样的实现中使用装饰器,但我觉得这里需要一个更好的方法:

@Component({
  selector: 'app-my-custom-list',
  templateUrl: '../../abstract-list/abstract-list.component.html',
  styleUrls: ['../../abstract-list/abstract-list.component.scss']
})
Run Code Online (Sandbox Code Playgroud)

是否可以使用@Component类似这样的装饰器?或者对于这种用法有什么技巧或最佳实践吗?

typescript angular angular8

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

使用 *ngIf 时如何防止闪烁?

在我的app.component.html中:

<html>
    <head></head>
    <body>
        <header *ngIf="loggedIn && showHeader"></header>
        <router-outlet></router-outlet>
    </body>
</html>
Run Code Online (Sandbox Code Playgroud)

在我的app.component.ts中:

export class AppComponent {

    constructor(private HeaderService: HeaderService, private AuthService: AuthService) { }

    get loggedIn(): boolean { return this.AuthService.getUserState(); }    
    get showHeader(): boolean { return this.HeaderService.getToggleState(); }
}
Run Code Online (Sandbox Code Playgroud)

在我的header.service.ts中:

我们创建此服务是因为登录后还有其他特定组件,其中标头也需要隐藏。

@Injectable({
    providedIn: 'root'
})

export class HeaderService {

    showHeader = true;

    constructor() { }

    setToggleState(state: boolean) {
       this.showHeader = state;
    }

    getToggleState() { return this.showHeader; }
}
Run Code Online (Sandbox Code Playgroud)

现在,在 my 中login.component,标题应该是不可见的。

现在发生的事情是,有一个短暂的闪烁时刻(似乎是在您登录然后注销并返回登录页面时发生),标题在隐藏之前是可见的(是的,也会抛出 …

html angular angular8

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