我已将我的 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) 下面是我在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) 我的基本存储库类
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) 我有下面的变量
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) 下面是我的代码:
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) 这是我的错误拦截器类。我需要向 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 …
我使用 ASP.NET Core 5 和 Entity Framework Core 作为我的 ORM。我从 Angular 应用程序获取 UTC 时间。但用户将仅来自一个国家。所以我决定将UTC时间转换为本地\xe2\x80\x94i.e印度的时区\xe2\x80\x94,同时保存到数据库。
\n我的问题:
\nen-IN
在存储到数据库时始终将 UTC 时间转换为 UTC 时间?请任何人建议该应用程序当地时间始终为en-IN
,但托管在相同/不同的国家/地区。
请告诉我如何将 UTC 时间转换为本地时间(en-IN),反之亦然
\n这是我的查询
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) 我正在设计一个使用 Sql 服务器作为后端的零售业务数据库。有一些产品是可以多卖的,比如铅笔可以卖一打,纸可以卖单、令、筒。基本上,每种产品都可以以多个单位出售。
App需要支持
下面是我的初始设计
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) 我正在尝试根据值 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) 如果发生任何错误,我需要一个全局异常处理程序来处理我的所有控制器方法(我需要向客户端发送一些错误代码)。目前正在每个控制器中编写 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) angular ×4
asp.net-core ×4
c# ×4
typescript ×3
postgresql ×2
rxjs ×2
sql-server ×2
asp.net ×1
c#-9.0 ×1
dapper ×1
exception ×1
promise ×1
sql ×1