在严格模式下使用 Angular 11 和 Typescript 4 我有:
export class ContactComponent implements OnInit {
form: FormGroup;
constructor(private formBuilder: FormBuilder) { }
ngOnInit() {
this.form = this.formBuilder.group({
email: ['', [Validators.required, Validators.email]],
name: ['', [Validators.required, Validators.maxLength(40)]],
});
}
Run Code Online (Sandbox Code Playgroud)
我收到构建错误:
Property 'form' has no initialiser and is not definitely assigned in the constructor.
Run Code Online (Sandbox Code Playgroud)
不应该在 ngOnInit 上初始化 FormGroup 吗?
我正在使用 Net 6 Minimal API:
application.MapGet("countries", async (IService service) => {
var countries = await mediator.Send(request);
return Results.Ok(countries);
});
Run Code Online (Sandbox Code Playgroud)
是否可以将 AspNet Api 版本控制与 Net 6 Minimal API 一起使用?如何?
我应该如何在Dapper中使用IDbConnection和IDbTransaction?
目前我只使用了一个IDbConnection
.如下:
using (SqlConnection connection = new SqlConnection(connectionString))
{
connection.Execute(@"insert Roles(Name) values (@name)", new { name = "Role" });
}
Run Code Online (Sandbox Code Playgroud)
但有时我需要发送2个命令?我应该使用BeginTransation
和EndTransaction
?
我有以下内容:
var data = new List<DataModel>();
Run Code Online (Sandbox Code Playgroud)
DataModel的位置如下:
public class DataModel {
public DateTime Date { get; set; }
public Int32 Users { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
如何将此List转换为JSON格式并在WebAPI 2.0操作中返回它?
谢谢你,米格尔
我有以下标记
<div>
<article>article 1</article>
<article>article 2</article>
<article>article 3</article>
<article>article 4</article>
<ul class="pagination">
<li>Page 1</li>
<li>Page 2</li>
</ul>
</div>
Run Code Online (Sandbox Code Playgroud)
我尝试对每篇文章应用底部边框,但不对最后一篇应用:
article:not(:last-child) {
border-bottom: 8px solid #404040;
}
Run Code Online (Sandbox Code Playgroud)
但是有了这个,我在上一篇文章中得到了一个边框.
如果我删除UL,那么上一篇文章没有边框.
这很奇怪,因为我只是将风格应用于文章.
我怎么解决这个问题?
谢谢你,米格尔
我正在创建一个SQL表来保存事务:
create table dbo.TRANSACTIONS
(
Id int identity not null,
Amount money not null
);
Run Code Online (Sandbox Code Playgroud)
对于货币(我使用欧元),我应该使用金钱,小数或数字吗?
我已经看到这三个应用于货币列,所以我不再确定了.
金钱将是明显的选择...但我已经看到了十进制和数字.
顺便说一下,我正在使用SQL Server 2012.
谢谢
我有以下方法:
public void Update<T>(T entity, IEnumerable<Expression<Func<T, Object>>> properties)
where T : class
{
_context.Set<T>().Attach(entity);
foreach (var property in properties)
_context.Entry<T>(entity)
.Property(((MemberExpression)property.Body).Member.Name)
.IsModified = true;
} // Update
Run Code Online (Sandbox Code Playgroud)
我正在传递一个Entity Framework实体,附加它并将每个属性设置为已修改.
我想用它如下:
_repository.Update<File>(file, new { x => x.Data, x => x.Name });
Run Code Online (Sandbox Code Playgroud)
所以我传递一个文件并说数据和名称属性被修改.
但是我收到了错误:
The best overloaded method match for 'Update<File>(File,
IEnumerable<System.Linq.Expressions.Expression<System.Func<File,Object>>>)'
has some invalid arguments
Run Code Online (Sandbox Code Playgroud)
如上所述,我应该如何更改我的方法才能使用它?
或者可能:
_repository.Update<File>(file, x => x.Data, x => x.Name);
Run Code Online (Sandbox Code Playgroud)
甚至:
_repository.Update<File>(file, x => new { x.Data, x.Name });
Run Code Online (Sandbox Code Playgroud) 在 SQL Server 中,我有以下包含学位级别的查找表:
create table dbo.DegreeLevel
(
Id int identity not null
constraint PK_DegreeLevel_Id primary key clustered (Id),
Name nvarchar (80) not null
constraint UQ_DegreeLevel_Name unique (Name)
)
Run Code Online (Sandbox Code Playgroud)
我应该在 上使用身份吗ID
?
我什么时候应该在查找表中使用identity或简单的int?
我需要一个以页面为中心的块引用,前后带有双引号Plunker 示例:
<div class="wrapper">
<blockquote>
<p>Quote text</p>
</blockquote>
</div>
Run Code Online (Sandbox Code Playgroud)
我有以下 CSS:
.wrapper {
text-align: center
}
blockquote {
margin: 0 auto;
max-width: 400px;
}
blockquote:after, blockquote:before {
color: @green;
font-size: 8.0rem;
line-height: 0.8;
}
blockquote:after {
content: close-quote;
vertical-align: bottom;
}
blockquote:before {
content: open-quote;
vertical-align: top;
}
p {
text-align: left;
font-size: 1.125rem;
font-style: italic;
}
Run Code Online (Sandbox Code Playgroud)
不知何故,我的引号被放置在块引用之前和之后。
我希望开头一个位于左上角位置,结尾一个位于右下位置......
我怎样才能做到这一点?
更新:
在ASP.NET MVC 6项目中,我有以下内容:
[Route("help/how-it-works")]
public IActionResult HowItWorks() {
return View();
}
Run Code Online (Sandbox Code Playgroud)
我想创建一个标签助手,如下所示:
<a class="menu" asp-controller="Help" asp-action="HowItWorks" route-is="help/how-it-works" css-class="active">How it works</a>
Run Code Online (Sandbox Code Playgroud)
所以route-is标签帮助器将检查当前路由是否为"help/how-it-works"...如果是,则将"active"添加到A标签的css类.
所以我开始创建一个标签助手:
[TargetElement("a", Attributes = "route-is, css-class")]
public class RouteTagHelper : TagHelper
{
public override void Process(TagHelperContext context, TagHelperOutput output)
{
String routeIs = context.AllAttributes["route-is"].ToString();
String cssClass = context.AllAttributes["css-class"].ToString();
if (String.IsNullOrWhiteSpace(cssClass))
cssClass = "active";
ViewContext.RouteData.Values.Keys;
}
}// Process
Run Code Online (Sandbox Code Playgroud)
我的问题是如何确定当前路由是否为"help/how-it-works",以及是否将Css类添加到A标记而不更改其他任何内容.
有没有人知道如何做到这一点?
更新1
使用属性路由时解决了重复值的问题,并添加了Daniel JG提出的替代方法
[TargetElement("a", Attributes = RouteIsName)]
[TargetElement("a", Attributes = RouteHasName)]
public class ActiveRouteTagHelper : TagHelper
{
private const String …
Run Code Online (Sandbox Code Playgroud) css ×2
sql-server ×2
.net-6.0 ×1
angular ×1
angular11 ×1
asp.net-core ×1
c# ×1
dapper ×1
html ×1
minimal-apis ×1
sql ×1
typescript ×1