小编Ljt*_*Ljt的帖子

类正在使用 Angular 功能,但未以 Angular 14 进行装饰

我已将我的 Angular 应用程序从 13 更新到 14。更新后,在 vs code 中打开组件类后出现以下错误。

类正在使用 Angular 功能,但未进行修饰。请添加显式的 Angular 装饰器

我已经检查过这个问题

但我没有在应用程序中使用任何继承性。

在此输入图像描述

但应用程序运行完美。如何消除该错误?

ts.confing

/* 要了解有关此文件的更多信息,请参阅: https: //angular.io/config/tsconfig。*/

{
  "compileOnSave": false,
  "compilerOptions": {
    
    "baseUrl": "./",
    "outDir": "./dist/out-tsc",
    "forceConsistentCasingInFileNames": false,
    "strict": false,
    "allowSyntheticDefaultImports":true, 
    "noImplicitOverride": true,
    "noPropertyAccessFromIndexSignature": true,
    "noImplicitReturns": true,
    "noFallthroughCasesInSwitch": true,
    "sourceMap": true,
    "declaration": true,
    "downlevelIteration": true,
    "experimentalDecorators": true,
    "moduleResolution": "node",
    "importHelpers": true,
    "target": "es2022",
    "module": "es2022",
    "lib": [
      "es2022",
      "dom"
    ],
    "paths": {
      "stream": [ "./node_modules/stream-browserify" ]
    },
  },
  "angularCompilerOptions": {
    "enableI18nLegacyMessageIdFormat": false,
    "strictInjectionParameters": …
Run Code Online (Sandbox Code Playgroud)

typescript angular

14
推荐指数
3
解决办法
7729
查看次数

Dapper多映射异步扩展

下面是我在dapper中进行多映射(一对多关系)的扩展

public static IEnumerable<TParent> QueryParentChild<TParent, TChild, TParentKey>(
    this IDbConnection connection,
    string sql,
    Func<TParent, TParentKey> parentKeySelector,
    Func<TParent, IList<TChild>> childSelector,
    dynamic param = null, IDbTransaction transaction = null, bool buffered = true, string splitOn = "Id", int? commandTimeout = null, CommandType? commandType = null)
{
    Dictionary<TParentKey, TParent> cache = new Dictionary<TParentKey, TParent>();

    connection.Query<TParent, TChild, TParent>(
        sql,
        (parent, child) =>
            {
                if (!cache.ContainsKey(parentKeySelector(parent)))
                {
                    cache.Add(parentKeySelector(parent), parent);
                }

                TParent cachedParent = cache[parentKeySelector(parent)];
                IList<TChild> children = childSelector(cachedParent);
                children.Add(child);
                return cachedParent;
            },
        param as object, transaction, …
Run Code Online (Sandbox Code Playgroud)

c# dapper asp.net-core

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

更新 TEntity 通用存储库上的父集合和子集合

我的基本存储库类

public class Repository<TEntity, TId> : IRepository<TEntity, TId> where TEntity : class, IEntity<TId>
{       
    protected readonly CBSContext _context;
    private DbSet<TEntity> _entities;
  
    public Repository(CBSContext context)
    {
        _context = context ?? throw new ArgumentNullException(nameof(context));
        _entities = _context.Set<TEntity>();
    }
    
    public async Task UpdateAsync(TEntity entity)
    {
        await Task.Run(() => _context.Entry(entity).State = EntityState.Modified);
       
    }

    //Update child enitity code added below 
}
Run Code Online (Sandbox Code Playgroud)

和我的实体接口

public interface IEntity<TId> 
{
    TId Id { get; set; }
}

public class Customer : IEntity<int>
{
    public int Id { get; set; …
Run Code Online (Sandbox Code Playgroud)

c# entity-framework-core

4
推荐指数
1
解决办法
1291
查看次数

在c#中将可为空的字符串转换为可为空的int

我有下面的变量

  int? a=null ;
    
  string? b= null;
Run Code Online (Sandbox Code Playgroud)

我需要分配 a=b ;

在 c# 9 中分配的最佳方式是什么

a= Convert.ToInt32(b);
Run Code Online (Sandbox Code Playgroud)

如果字符串也为空,则分配 0 ..hw 以分配空。我需要在 c# 9 中知道

编辑:感谢@john .. 我最终得到了以下代码

  if(b is not null) 
     a = Convert.ToInt32(b); 
Run Code Online (Sandbox Code Playgroud)

c# c#-9.0

4
推荐指数
1
解决办法
220
查看次数

forkjoin 在 Angular 10 替代方案中已弃用

下面是我的代码:

 async getBranchDetails()  ----component  method

  {
    let banks = this.bankDataService.getBanks();
    let branchTypes = this.branchDataService.getBranchTypes();

    forkJoin([banks,branchTypes]).subscribe(results => {
              this.setFormBankData(results[0]);
              this.setFormBranchTypeData(results[1]);
            });
  }
Run Code Online (Sandbox Code Playgroud)

- - 服务

 async getBanks(): Promise<IBankResponse[]> {
        return await  this.httpClient.get<Result<IBankResponse[]>>(baseUrl + '/Bank/GetBanks')
        .pipe(map( res => res.data)).toPromise();
    }
Run Code Online (Sandbox Code Playgroud)

Fork join 显示已弃用。是否有任何其他用途async/ await。谢谢。

编辑:我不知道它是否正确,但使用了 asyn/await ..我的最终代码如下

  async getBranchDetails()

  {
    let banks =  await this.bankDataService.getBanks();
    let branchTypes= await this.branchDataService.getBranchTypes();
    this.setFormBankData(banks);
    this.setFormBranchTypeData(branchTypes);
   
  }
Run Code Online (Sandbox Code Playgroud)

promise rxjs typescript angular

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

http 错误拦截器不起作用 CatchError 不适用于 Angular 13

这是我的错误拦截器类。我需要向 cComponent 类可观察方法抛出错误错误:我已经检查过throwError(error) 现已弃用,但没有新的 Error(HttpErrorResponse)

@Injectable()
export class HttpErrorInterceptor implements HttpInterceptor {
    constructor(private toastr: ToastrService,private authService: AuthService,
        private router:Router) {
    }

    intercept( request: HttpRequest<any>, next: HttpHandler ): Observable<HttpEvent<any>> {
      return next.handle(request)
          .pipe(
              catchError((error: HttpErrorResponse) => {

                debugger
                  let message = '';
                  if (error.error instanceof ErrorEvent) {
                      // handle client-side error
                      message = `Error: ${error.error.message}`;
                      this.toastr.error(message);
                  } else {
                      // handle server-side error
                      debugger
                    
                      message = `Error: ${ error?.error?.Message || error?.statusText}`; 
                      if(!error.status)
                      {
                          this.toastr.error('Not able connect to server');                        
                      }
Run Code Online (Sandbox Code Playgroud)

else …

rxjs typescript angular

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

ASP.NET Core UTC 时间转本地时间

我使用 ASP.NET Core 5 和 Entity Framework Core 作为我的 ORM。我从 Angular 应用程序获取 UTC 时间。但用户将仅来自一个国家。所以我决定将UTC时间转换为本地\xe2\x80\x94i.e印度的时区\xe2\x80\x94,同时保存到数据库。

\n

我的问题:

\n
    \n
  1. 如何将 ASP.NET Core 应用程序配置为en-IN在存储到数据库时始终将 UTC 时间转换为 UTC 时间?
  2. \n
  3. 另外,在将数据发送到 API 时,我需要将本地时间转换回 UTC。
  4. \n
\n

请任何人建议该应用程序当地时间始终为en-IN,但托管在相同/不同的国家/地区。

\n

请告诉我如何将 UTC 时间转换为本地时间(en-IN),反之亦然

\n

postgresql asp.net-core angular asp.net-core-5.0

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

EF core 5 多对多过滤器

这是我的查询

 public async Task<IEnumerable<Menu>> GetMenuByRolesAsync(string[] roles)
        {
    var result= await _context.Menus//.Include(o => o.Parent)
                                     .Include(m => m.Childrens)
                                     .ThenInclude(m => m.Childrens)
                                     .Include(m => m.Roles.Where(r => roles.Contains(r.Name)))   --it is not filtering basd on roles                          
                                     .Where(m => m.ParentId == null)
                                     .ToListAsync();
}
Run Code Online (Sandbox Code Playgroud)

它正在生成以下查询

-- @__roles_0='System.String[]' (DbType = Object)
SELECT m.id, m.icon, m.name, m.parent_id, m.url, t.role_id, t.menu_id, t.id, t.concurrency_stamp, t.name, t.normalized_name
FROM security.menu AS m
LEFT JOIN (
    SELECT r.role_id, r.menu_id, r0.id, r0.concurrency_stamp, r0.name, r0.normalized_name
    FROM security.role_menu AS r
    INNER JOIN security.role AS r0 ON …
Run Code Online (Sandbox Code Playgroud)

postgresql entity-framework-core asp.net-core

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

多单元产品的数据库设计

我正在设计一个使用 Sql 服务器作为后端的零售业务数据库。有一些产品是可以多卖的,比如铅笔可以卖一打,纸可以卖单、令、筒。基本上,每种产品都可以以多个单位出售。

App需要支持

  • 可以从多个单位的供应商处接收产品。有时我们可能会订购 1 支铅笔,下次我们会订购 2 盒铅笔。
  • 可以以多个单位销售产品,例如,我们必须能够在同一张账单中销售 1 盒和 2 支铅笔。
  • 应用程序还需要支持先进先出或后进先出

下面是我的初始设计

Table: Products
ProductId | Barcode | Name   | BaseUnitId
1         | XXXX    | Pencil | 1

Table: Units
UnitId | Name
1      | Each / Pieces
2      | Box

Table: UnitConversion
ProductId | BaseUnitId | Multiplier | ToUnitId |
1         | 1          | 24         | 2        | // 24 pencils in a box

Table: Inventories
Id | ProductId | UnitId | Quantity 
1  | …
Run Code Online (Sandbox Code Playgroud)

sql sql-server sql-server-2008

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

基于指定值的分区

我正在尝试根据值 90 编写 q 查询哪个分区。下面是我的表

create table  #temp(StudentID char(2),    Status int) 
insert #temp  values('S1',75 ) 
insert #temp  values('S1',85 )
insert #temp  values('S1',90)
insert #temp  values('S1',85)
insert #temp  values('S1',83)
insert #temp  values('S1',90 ) 
insert #temp  values('S1',85)
insert #temp  values('S1',90)
insert #temp  values('S1',93 ) 
insert #temp  values('S1',93 ) 
insert #temp  values('S1',93 ) 
Run Code Online (Sandbox Code Playgroud)

要求输出:

ID  Status  Result
S1  75      0
S1  85      0
S1  90      0
S1  85      1
S1  83      1
S1  90      1
S1  85      2
S1  90      2
S1  93 …
Run Code Online (Sandbox Code Playgroud)

sql-server sql-server-2008

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

asp.net core 2.2 或 3 中 try catch 的全局异常

如果发生任何错误,我需要一个全局异常处理程序来处理我的所有控制器方法(我需要向客户端发送一些错误代码)。目前正在每个控制器中编写 try catch 块。下面是我的控制器方法。这很好吗?方法或请建议我使用 asp.net core 3 预览版的解决方案/方法。

[HttpPost]
        public ActionResult<Caste> InsertCaste(CasteModel caste)
        {
            try
            {

                var result = casteService.InsertCaste(caste);

                return CreatedAtAction(nameof(InsertCaste), new { id = result.Id }, result);
            }
            catch (Exception ex)
            {
                Log.Logger.log().Error(ex.Message);
                return null;
            }
        }
Run Code Online (Sandbox Code Playgroud)

c# asp.net exception asp.net-core

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