小编Ton*_*Ngo的帖子

Angular 8-延迟加载模块:错误TS1323:仅当'--module'标志为'commonjs'或'esNext'时才支持动态导入

当我将Angular从7更新到Angular 8时,出现延迟加载模块错误

我尝试了角度升级指南中提供的选项

进行了以下更改:

之前

    loadChildren: '../feature/path/sample- 
                         tage.module#SameTagModule'
Run Code Online (Sandbox Code Playgroud)

   loadChildren: () => import('../feature/path/sample- 
                      tags.module').then(m => m.CreateLinksModule)
Run Code Online (Sandbox Code Playgroud)

错误TS1323:仅当'--module'标志为'commonjs'或'esNext'时,才支持动态导入。

javascript module typescript angular angular8

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

在asp.net核心项目中获取Azure Active Directory组

我使用Visual Studio 2015创建了一个新项目,并使用Azure Active Directory的工作和学校帐户启用了身份验证.以下是生成的configure函数的外观:

app.UseStaticFiles();
app.UseCookieAuthentication();
app.UseOpenIdConnectAuthentication(new OpenIdConnectOptions
{
    ClientId = Configuration["Authentication:AzureAd:ClientId"],
    ClientSecret = Configuration["Authentication:AzureAd:ClientSecret"],
    Authority = Configuration["Authentication:AzureAd:AADInstance"] + Configuration["Authentication:AzureAd:TenantId"],
    CallbackPath = Configuration["Authentication:AzureAd:CallbackPath"],
    ResponseType = OpenIdConnectResponseType.CodeIdToken
});

app.UseMvc(routes =>
{
    routes.MapRoute(
        name: "default",
        template: "{controller=Home}/{action=Index}/{id?}");
});
Run Code Online (Sandbox Code Playgroud)

以下是尝试获取用户组的基本操作代码:

public async Task<IActionResult> Index()
{
    var client = new HttpClient();
    var uri = "https://graph.windows.net/myorganization/users/{user_id}/$links/memberOf?api-version=1.6";

    var response = await client.GetAsync(uri);
    if (response.Content != null)
    {
        ViewData["response"] = await response.Content.ReadAsStringAsync();
    }

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

我需要使用或更改此代码以确保我可以获得用户组?目前,回应是:

{  
   "odata.error":{  
      "code":"Authentication_MissingOrMalformed",
      "message":{  
         "lang":"en",
         "value":"Access Token missing or …
Run Code Online (Sandbox Code Playgroud)

c# azure-active-directory asp.net-core .net-core-rc2

29
推荐指数
1
解决办法
3252
查看次数

如何使用 Visual Studio 2019 在 ASP.NET Core 2.2 中安装 Font Awesome

我正在努力寻找在 ASP.NET Core 2.2 中安装 Font Awesome 的任何最新安装指南

我已经尝试将手动文件导入到项目文件夹目录,然后尝试了 NuGet 包路由,但没有任何效果,因为我遵循的所有指南都参考了 2.2 中不存在的步骤和文件夹/文件

刚接触 ASP.NET Core 可能无济于事:(

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

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

如何使用泛型类型注册依赖注入?(.net 核心)

我在 appSettings.json 文件中有一个带有多个参数的 asp.net 核心 Web 应用程序。

我不想IOptions<MyObject>在构造函数中提供服务。

我想在构造函数中使用 MyObject。所以我找到了以下文章:https : //weblog.west-wind.com/posts/2017/dec/12/easy-configuration-binding-in-aspnet-core-revisited,这很有趣。

但我想更进一步。我想创建一个扩展方法来生成注入。

这是我想做的事情:

using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;

namespace Common.WebTools.Extensions
{
    public static class IServiceCollectionExtensions
    {
        public static IServiceCollection AddSingletonConfigurationObject<T>(this IServiceCollection services, 
            IConfiguration configuration,
            string appSettingsKey) where T:new()
        {   
            var obj2 = new T();
            configuration.Bind(appSettingsKey, obj);
            services.AddSingleton(obj2); //compilation failed
            return services;
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

然后在我的 ConfigureServices 方法中我可以调用

services.AddSingletonConfigurationObject<Common.Tools.Configuration.GoogleAnalyticsConfiguration>(Configuration, "GoogleAnalytics");
Run Code Online (Sandbox Code Playgroud)

但我在这一行有一个编译错误:

services.AddSingleton(obj2); 
Run Code Online (Sandbox Code Playgroud)

有人知道我该如何纠正错误吗?

c# dependency-injection asp.net-core-mvc .net-core asp.net-core

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

GENERATE_SOURCEMAP=false 问题

在 Windows 中,当我尝试构建 React 应用程序时,我收到错误消息,提示“GENERATE_SOURCEMAP”未被识别为内部或外部命令。

我在 package.json 文件中添加了以下行

"build": "GENERATE_SOURCEMAP=false react-scripts build"
Run Code Online (Sandbox Code Playgroud)

windows build node.js reactjs webpack

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

Webpack 将 scss 编译为 css 并缩小

我是 webpack 的新手,我正在努力如何将 scss 转换为 css 然后缩小。

文件结构

 public
     ? dist
     ? ? css
     ? ? js
     ? ? ? adminMain.js
     ? src
     ? ? css
     ? ? ? ? admin.css
     ? ? ? ? admin.css.map
     ? ? ? ? admin.scss
     ? ? ? ? main.css
     ? ? ? ? main.css.map
     ? ? ? ? main.scss
     ? ? js
     ? ? ? adminMain.js
Run Code Online (Sandbox Code Playgroud)

我正在像这样编译js

"dev": "webpack --mode development ./public/src/js/adminMain.js --output ./public/dist/js/adminMain.js",
"build": "webpack --mode production ./public/src/js/adminMain.js --output ./public/dist/js/adminMain.js"
Run Code Online (Sandbox Code Playgroud)

我找到了类似的东西,sass-loader …

javascript css sass node.js webpack

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

NET Core 3 Preview 8升级后反应SPA / Embedded Identity Server问题

我们有一个React SPA,它最初是使用SPA模板创建的,并在.NET Core 3预览版7上运行。ReactSPA“客户端”已配置为隐式流,并成功使用了oidc-client。一切正常。

这是我的startup.cs中的客户端配置:

        var mySPAClient = new IdentityServer4.Models.Client()
        {
            AccessTokenLifetime = accessTokenLifetime,
            RedirectUris =
                {
                    $"{host}/authentication/login-callback",
                    $"{host}/silent-refresh.html"
                },
            PostLogoutRedirectUris =
                {
                    $"{host}/authentication/logout-callback"
                },
            ClientId = "projectName.web",
            AllowedScopes =
                {
                    "projectName.webAPI",
                    "openid",
                    "profile"
                },
            ClientName = "projectName.web",
            RequireConsent = false,
            AllowedGrantTypes =
                {
                    IdentityModel.OidcConstants.GrantTypes.Implicit
                },
            AllowAccessTokensViaBrowser = true,
        };
Run Code Online (Sandbox Code Playgroud)

但是现在当我升级到任何预览版本为7的程序集的预览版本8时,日志中都会出现以下错误

[10:55:34错误] 客户端的无效授权类型:“ authorization_code” AuthorizeRequestValidationLog {ClientId:“ projectName.web”,ClientName:“ projectName.web”,RedirectUri:“ https:// localhost:44343 / authentication / login-回调 “,AllowedRedirectUris:[” https:// localhost:44343 / authentication / login-callback “,” https:// localhost:44343 / silent-refresh.html“],SubjectId:”匿名“,ResponseType:”代码“,ResponseMode:”查询“,GrantType:” authorization_code“,RequestedScopes:”“,状态:” a1e84334a8c94b7db599ddb9336447c8“,UiLocales:null,Nonce:null,AuthenticationContextReferenceClasses:null, DisplayMode:null,PromptMode:null,MaxAge:null,LoginHint:null,SessionId:null,Raw:[(“ …

c# node.js reactjs asp.net-core identityserver4

12
推荐指数
1
解决办法
377
查看次数

“如果没有描述,‘@param’在 TypeScript 代码中是多余的。” TSLint 错误?

我有一个 Angular 8 项目,我运行ng lint.

即使我有一个@description与特定方法相关联的装饰器,TSLint 也会抱怨并说:"'@param' is redundant in TypeScript code if it has no description."在我的代码中的不同地方。

例如,上述错误会显示当一个方法是这样编写的(TypeScript):

  /**
   * @description my lovely description
   * @param empDetails
  */
  getHeaderBasedonEmpDetails(empDetails: EmployeeDetails) {
    if (someVar) {
      return 'yeah'
    } else {
      return 'nah'
    }
  }
Run Code Online (Sandbox Code Playgroud)

包.json:

{
  "name": "example-app",
  "version": "0.0.0",
  "private": true,
  "dependencies": {
    "@angular/animations": "^8.0.0",
    "@angular/cdk": "^8.0.0",
    "@angular/common": "^8.0.0",
    "@angular/compiler": "^8.0.0",
    "@angular/core": "^8.0.0",
    "@angular/flex-layout": "^8.0.0-beta.26",
    "@angular/forms": "^8.0.0",
    "@angular/http": "^7.2.15",
    "@angular/language-service": "^8.0.0",
    "@angular/material": "^6.3.3",
    "@angular/material-moment-adapter": …
Run Code Online (Sandbox Code Playgroud)

single-page-application typescript ecmascript-6 angular angular8

11
推荐指数
1
解决办法
2952
查看次数

在 TypeScript 中使用 JS React 组件:JSX 元素类型“MyComponent”不是 JSX 元素的构造函数

我正在处理一个使用 React 框架的 JavaScript 遗留项目。我们定义了一些 React 组件,我想在一个完全不同的 TypeScript React 项目中重用它们。

JS React 组件在 control.jsx 文件中定义,如下所示:

export class MyComponent extends React.Component {
  render() {
    return <h1>Hi from MyComponent! Message provided: {this.props.message}</h1>;
  }
}
Run Code Online (Sandbox Code Playgroud)

在我的 TypeScript React 项目中,我试图这样使用它:

import * as React from "react";
import * as ReactDOM from "react-dom";
import { MyComponent } from "../JavaScriptProject/controls";

ReactDOM.render(
  <MyComponent message="some nice message"/>,
    document.getElementById("documents-tree")
);
Run Code Online (Sandbox Code Playgroud)

但我收到以下错误: 在此处输入图片说明

错误消息说:

JSX 元素类型“MyComponent”不是 JSX 元素的构造函数。“MyComponent”类型缺少“ElementClass”类型中的以下属性:context、setState、forceUpdate、props 和另外 2 个。ts(2605) JSX 元素类不支持属性,因为它没有“props”属性。ts (2607)

我已经尝试过使用问题中描述的自定义类型文件的解决方案,但它没有任何改变。

我知道 JS 组件缺少 TypeScript …

javascript node.js single-page-application typescript reactjs

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

ng build --prod index.html 文件没有生成后?

在生产模式下构建项目后,我将 Angular 7 更新为 8.2.1,dist 文件夹不生成index.html文件

tsconfig.json

{
  "compileOnSave": false,
  "compilerOptions": {
    "baseUrl": "./",
    "outDir": "./dist/out-tsc",
    "sourceMap": true,
    "declaration": false,
    "module": "esnext",
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "target": "es5",
    "paths": {
      "exceljs": [
        "node_modules/exceljs/dist/exceljs.min"
      ]
    },
    "typeRoots": [
      "node_modules/@types"
    ],
    "lib": [
      "es2018",
      "dom"
    ],

  }
}
Run Code Online (Sandbox Code Playgroud)

分布/AssetMang/ 角度.json

{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "version": 1,
  "newProjectRoot": "projects",
  "projects": {
    "AssetMang": {
      "root": "",
      "sourceRoot": "src",
      "projectType": "application",
      "prefix": "app",
      "schematics": {},
      "architect": {
        "build": {
          "builder": "@angular-devkit/build-angular:browser",
          "options": { …
Run Code Online (Sandbox Code Playgroud)

typescript angular

10
推荐指数
1
解决办法
6082
查看次数