小编Ton*_*Ngo的帖子

使用 ReactJS SPA 在 .net Core 中进行身份验证

我尝试向 .net Core 2.1 应用程序添加身份验证。从头开始:我们可以使用 VS 模板通过 React 创建新的 Web 应用程序。

在这个模板中我们可以看到:

app.UseSpa(spa =>
{
    spa.Options.SourcePath = "ClientApp";
    spa.ApplicationBuilder.UseAuthentication();


    if (env.IsDevelopment())
    {
        spa.UseReactDevelopmentServer(npmScript: "start");
    }
});
Run Code Online (Sandbox Code Playgroud)

我还添加了身份验证控制器和带有登录/注册端点的视图。

如何添加拒绝访问 SPA 直到我们登录应用程序的逻辑?

我知道如何使用 asp.net 身份监管,但对于这个 SPA,我需要建议。

c# reactjs asp.net-core-mvc .net-core asp.net-core

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

当我在服务器中部署时,Angular Service Worker 离线缓存不起作用

当我使用 angular/pwa 构建我的 angular 项目并使用 http-server 在本地服务器上对其进行测试时,它按预期工作。即使离线缓存在本地也能正常工作。

但是当我在服务器中部署相同的东西时,我能够在任何设备上安装和运行它,但在我离线时无法打开。

服务工作者没有缓存 angular pwa 中的内容

这是我的 app.module.ts

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { HttpClientModule } from '@angular/common/http';

import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { GetchucknorrisjokesService } from './getchucknorrisjokes.service';
import { ServiceWorkerModule } from '@angular/service-worker';
import { environment } from '../environments/environment';

@NgModule({
  declarations: [
    AppComponent,
  ],
  imports: [
    BrowserModule,
    AppRoutingModule,
    HttpClientModule,
    ServiceWorkerModule.register('ngsw-worker.js', { enabled: environment.production })
  ],
  providers: [ …
Run Code Online (Sandbox Code Playgroud)

javascript typescript service-worker progressive-web-apps angular

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

.Net Core项目默认不会打开浏览器

在 VS 2019 中调试时,api url 自动打开,这与 Angular Live url 不同。

角度实时网址是我实际的完整应用程序。有没有办法在调试时自动打开该网址?

c# json asp.net-core-mvc .net-core asp.net-core

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

我的 NgRx 效果不起作用,什么也没发生

我的 NgRx 效果有问题。

应用程序正确添加到商店,不幸的是我的请求效果没有执行,即在启动添加新车时,将其添加到商店,就是这样。问题是我的效果没有控制台日志,没有由于错误的 url 导致的 http 错误,什么都没有。

我的应用程序代码:

减速器

import { Action } from '@ngrx/store';
import * as CarActions from './car.actions';
import { Car } from 'src/models/car.model';

const initialState: Car = {
   brand: '',
   model: ''
};

export function carReducer(state: Car[] = [initialState], action: CarActions.Actions) {

    switch (action.type) {
        case CarActions.ADD_CAR:
            return [...state, action.payload];
        case CarActions.ADD_CAR_FAIL:
            return {
                ...state,
                carError: action.payload,
            };
        default:
            return state;
    }
}
Run Code Online (Sandbox Code Playgroud)

状态

import { Car } from './../../models/car.model';

export interface AppState {
  readonly …
Run Code Online (Sandbox Code Playgroud)

rxjs typescript redux ngrx angular

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

如何在猫鼬中通过用户ID一次选择两个表(文档)值?

我正在使用 NodeJs、ExpressJs 以及 Mongodb 和 Mongoose。我想通过用户 ID 选择两个文档的值。

我有三个模型用户、学术模型和职业模型。我已通过用户模式的 _id 与学术和职业模式建立了关系。我在这些文档中保存了一些值。现在我想通过用户 ID 选择学术和职业的文档值。

模型

 // user model
    const userSchema = new mongoose.Schema({
        name: {type: String},
        email: {type: String},
    });
    const user = mongoose.model('User', userSchema);

    // academic model
    const academicSchema = new mongoose.Schema({
        academicLevel: {type: String},
        passYear: {type: Number},
        user: {
            type: mongoose.Schema.Types.ObjectId,
            ref: 'User'
        }
    });
    const academic = mongoose.model('Academic', academicSchema);

    // career model
    const careerSchema = new mongoose.Schema({
        jobTitle: {type: String},
        company: {type: String},
        user: {
            type: mongoose.Schema.Types.ObjectId,
            ref: …
Run Code Online (Sandbox Code Playgroud)

javascript mongoose mongodb node.js

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

Webpack TerserPlugin - 排除节点模块

使用自定义 Angular Builder,我尝试将整个模块排除在缩小/优化之外。

Webpack.md文件说

类型
:String|RegExp|Array 默认值:undefined

要排除的文件。

我可以使用此设置来排除整个目录(即节点模块)吗?


当前的代码是

export default class CustomizeTerserBrowserBuilder extends BrowserBuilder {
  public buildWebpackConfig(root: any, projectRoot: any, host: any, options: any): any {
    const webpackConfig = super.buildWebpackConfig(root, projectRoot, host, options);

    if (
      webpackConfig.optimization &&
      webpackConfig.optimization.minimizer &&
      Array.isArray(webpackConfig.optimization.minimizer)
    ) {
      const terserPlugin = (webpackConfig.optimization.minimizer as any[]).find(
        minimizer => minimizer instanceof TerserPlugin
      );

      if (terserPlugin) {
        terserPlugin.options.exclude = [/node_modules/];
      }
    }

    return webpackConfig;
  }
}
Run Code Online (Sandbox Code Playgroud)

single-page-application typescript ecmascript-6 webpack angular

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

RXJS 6处理http Observable的方式是什么?

我注意到当我在新项目中使用它时,我的代码不起作用:

import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs';

import { TypeAndCountURL } from '@app/constants';
import { HttpErrorService } from '@app/services/http-error.service';
import { TypeAndCountResponseBody, TypeAndCountRequestBody } from '@app/models/type-and-count/bodies.interface';

@Injectable({
  providedIn: 'root'
})
export class ApiService {
  constructor (private http: HttpClient, private httpErrorService: HttpErrorService) {}

  postTypeAndCountRequest(typeAndCountRequestBody: TypeAndCountRequestBody): Observable<TypeAndCountResponseBody> {
    return this.http.post<TypeAndCountResponseBody>(TypeAndCountURL, typeAndCountRequestBody).pipe(
      catchError(this.httpErrorService.handleError<TypeAndCountResponseBody>('postTypeAndCountRequest'))
    );

  }
}
Run Code Online (Sandbox Code Playgroud)

具体来说,我正在 Cannot find name 'catchError'. Did you mean 'RTCError'?ts(2552)

仔细阅读,我可以通过单独导入来解决问题(从rxjs / operators .. whihc很好,但是)..而且整个结构都是rxjs 5的兼容模式...什么是RXJS …

javascript rxjs typescript angular

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

如何在angular 2中的多个模块中使用指令

我在两个模块中声明指令,然后返回错误为,Type PermissionDirective is part of the declarations of 2 modules而我仅声明一个模块,然后返回错误为Can't bind to 'isPermission' since it isn't a known property of 'button'。这里有什么问题。

请了解我的应用程序结构。

权限指令

import { Directive, Input } from '@angular/core';
import { TemplateRef, ViewContainerRef } from '@angular/core';
import { LoginInfoService } from '../service/auth.service';

@Directive({ selector: '[isPermission]' })
export class PermissionDirective {
  constructor(
    private templateRef: TemplateRef<any>,
    private viewContainer: ViewContainerRef,
    private _auth: LoginInfoService
  ) {
  }
  @Input() set isPermission(_module_action: Array<string>) {
    let permission = this._auth.isPermission(_module_action[0], _module_action[1]);
    if (permission) …
Run Code Online (Sandbox Code Playgroud)

javascript module typescript ecmascript-6 angular

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

如何以角度向 httpRequest 添加自定义标头

我试图做一个http get()通过传递某些请求valuesheaders,现在我更换headers这样的:

import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Injectable } from '@angular/core';
import {ICustomer} from 'src/app/models/app-models';

@Injectable({
  providedIn: 'root'
})
export class MyService {
private baseUrl = '....api url....';
public authKey = '....auth_key......';

  constructor(private http: HttpClient) { }

  public async AllCustomers(): Promise<ICustomer[]> {
   const apiUrl = `${this.baseUrl}/customers`;

   return this.http.get<ICustomer[]>(apiUrl ,
    {headers: new HttpHeaders({Authorization: this.authKey})}).toPromise();<=====
  }

}
Run Code Online (Sandbox Code Playgroud)

当我像这样替换标题时:

headers: new HttpHeaders({Authorization: this.authKey})

默认标头值(即 Content-Type : application/json)将被上述标头替换。

在此处输入图片说明 我没有替换标题如何添加custom headers,而是像这样尝试: …

javascript node.js rxjs typescript angular

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

TypeScript function to set height in NgStyle does not work

I have designed a shape and I want to determine its height based on a TypeScript-function, but the ngStyle does not apply the height to the shape.

HTML:

<div class = "card" [ngStyle] = "{'height': CalculateHeight()}" (click) = 'onSelect()'>
Run Code Online (Sandbox Code Playgroud)

Function:

CalculateHeight(): number {
  let CardHeight = ((this.Card.duration.Hours * 60) +
    (this.Card.duration.Minutes)) * 2;

  if (CardHeight <= 60) {
    CardHeight = 60;
  }

  console.log(CardHeight);

  return CardHeight;
}
Run Code Online (Sandbox Code Playgroud)

What is the problem?

css single-page-application typescript ecmascript-6 angular

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