我尝试向 .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,我需要建议。
当我使用 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
在 VS 2019 中调试时,api url 自动打开,这与 Angular Live url 不同。
角度实时网址是我实际的完整应用程序。有没有办法在调试时自动打开该网址?
我的 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) 我正在使用 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) 使用自定义 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
我注意到当我在新项目中使用它时,我的代码不起作用:
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 …
我在两个模块中声明指令,然后返回错误为,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) 我试图做一个http get()通过传递某些请求values中headers,现在我更换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)将被上述标头替换。
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?
angular ×7
typescript ×7
javascript ×5
ecmascript-6 ×3
rxjs ×3
.net-core ×2
asp.net-core ×2
c# ×2
node.js ×2
css ×1
json ×1
module ×1
mongodb ×1
mongoose ×1
ngrx ×1
reactjs ×1
redux ×1
webpack ×1