在Angular 4应用程序中,我有一个这样的表单模型:
this.form = this._fb.group({
title: ['', [Validators.required, Validators.minLength(3), Validators.maxLength(50)]],
description: ['', [Validators.required, Validators.minLength(3)]]
});
Run Code Online (Sandbox Code Playgroud)
现在我想要的是从控制验证器数组中仅动态删除所需的验证器.像这样的东西:
saveDraft() {
this.form.controls['title'].removeValidator('required'); //Just a fake implementation for demonstration
}
Run Code Online (Sandbox Code Playgroud)
这个问题不是上述问题的重复.我的情况不同我只想在不知不觉中删除所需的验证器.
我正在使用ASP.NET Core 2.0默认模型验证,ModelState.IsValid尽管模型中存在错误数据,但似乎无法使用始终为真.
[HttpPost("abc")]
public async Task<IActionResult> Abc([FromBody]AbcViewModel model)
{
if (!ModelState.IsValid) { return BadRequest(ModelState); }
...
}
public class AbcViewModel
{
[Required(ErrorMessage = "Id is required")]
[Range(100, int.MaxValue, ErrorMessage = "Invalid Id")]
public int Id { get; set; }
public bool Status { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
当我从Angular应用程序发布数据时,值正确映射到模型,但如果Id为"0"或小于100,则验证器Required和Range验证器都不起作用且ModelState.IsValid始终为true.我错过了什么?
所以我的目标是为单个 li 的子元素创建一个 mouseenter/mouseexit 事件。对于我的应用程序,当用户鼠标进入 li 元素时,它的子元素div class='thumbs'通过名为“hover”的组件布尔属性添加到 DOM -- *" ngIf='hover'"
我的问题是,当我鼠标悬停在单个 li 元素上时,会显示所有拇指图标,而不仅仅是单个 li 的拇指图标。
这是一个视频,突出了我的问题:
HTML:
<ul> <!-- Each song on the album -->
<li class="song-block"
*ngFor='let song of songsToDisplay'
(click)="getSong(song)"
(mouseenter)="hoverStateIn()"
(mouseleave)="hoverStateOut()">
<div class="song-card"
(click)="addPlay(song)">
<p *ngIf="!song.isPlaying"
class="song-number">{{song.tracknumber}}</p>
<i *ngIf="song.isPlaying" class="fa fa-play"></i>
<p class="song-name">{{song.name}}</p>
<p class="song-length">{{song.length}}</p>
<div class="thumbs"
*ngIf="hover"> <!-- Thumbs section -->
<i class="fa fa-thumbs-up"></i>
<i class="fa fa-thumbs-down"></i>
</div>.....
</ul>
Run Code Online (Sandbox Code Playgroud)
打字稿:
hover: boolean = false;
hoverStateIn(){
this.hover = true
}
hoverStateOut(){
this.hover = …Run Code Online (Sandbox Code Playgroud) 我有两个约会:
DateTime fromDate = new DateTime(2013,7,27,12,0,0);
DateTime toDate = new DateTime(2013,7,30,12,0,0);
Run Code Online (Sandbox Code Playgroud)
我想通过从一天开始递增fromDate来从fromDate迭代到toDate,并且当fromDate等于或大于toDate时循环应该中断.我试过这个:
while(fromDate < toDate)
{
fromDate.AddDays(1);
}
Run Code Online (Sandbox Code Playgroud)
但这是一个无限循环,不会停止.我怎样才能做到这一点 ?
我在Angular Material 2中创建了自定义主题,现在我想使用自定义主题更改默认的主体背景颜色.我认为可以通过在theming.scss文件中使用此映射对象来更改/覆盖它:
$mat-light-theme-background: (
status-bar: map_get($mat-grey, 300),
app-bar: map_get($mat-grey, 100),
background: map_get($mat-grey, 50), //To override this property
hover: rgba(black, 0.04), // TODO(kara): check style with Material Design UX
card: white,
dialog: white,
disabled-button: $black-12-opacity,
raised-button: white,
focused-button: $black-6-opacity,
selected-button: map_get($mat-grey, 300),
selected-disabled-button: map_get($mat-grey, 400),
disabled-button-toggle: map_get($mat-grey, 200),
unselected-chip: map_get($mat-grey, 300),
disabled-list-option: map_get($mat-grey, 200),
);
Run Code Online (Sandbox Code Playgroud)
但是如何background从我的自定义主题更改此属性?这是我的自定义主题文件中的内容:
@import '~@angular/material/theming';
$typography: mat-typography-config( $font-family: 'Roboto, sans-serif', $body-1: mat-typography-level(13px, 18px, 400) );
@include mat-core($typography);
$primary: mat-palette($mat-indigo);
$accent: mat-palette($mat-pink, A200, A100, …Run Code Online (Sandbox Code Playgroud) 我在登录时在来自 DB 的访问令牌中添加了一些声明(例如entity_id和role)。现在在某个阶段,entity_id声明已更改,我需要使用更新的声明获取新的访问令牌。我正在使用刷新令牌来获取新的访问令牌,但它内部带有相同的旧声明;可能是因为在IResourceOwnerPasswordValidator刷新令牌的情况下没有调用实现类。那么如何在访问令牌中获取更新的声明呢?因为用户必须注销并重新登录才能更新entity_id和role声明。
我知道另一种选择是使用/userinfo端点进行声明,但我的问题是在这种情况下[Authorize(Roles = "Manager")],ASP.NET Core的属性将如何工作并了解角色,如果它们不存在于访问令牌中?
我在编辑操作中创建了一个ViewBag选择列表,并将值设置为:
ViewBag.Doors = new SelectList(
new[]
{
new {ID = 1, Name="1-Door"},
new {ID = 2, Name="2-Doors"},
new {ID = 3, Name="3-Doors"},
new {ID = 4, Name="4-Doors"},
new {ID = 5, Name="5-Doors"},
new {ID = 6, Name="6-Doors"},
new {ID = 7, Name="7-Doors"}
},
"ID", "Name", advert.Doors);
Run Code Online (Sandbox Code Playgroud)
但在视图中,默认情况下不会选择下拉列表的值.
我的观看代码是:
@Html.DropDownListFor(model => model.Doors, (SelectList)ViewBag.Doors, "--Select--")
@Html.ValidationMessageFor(model => model.Doors)
Run Code Online (Sandbox Code Playgroud)
物业门将是数字1,2,3,..
advert.AC = String.IsNullOrEmpty(reader["AC"].ToString()) ? null : Byte.Parse(reader["AC"].ToString());
Run Code Online (Sandbox Code Playgroud)
我想在读取器["AC"]中存在空记录时将null分配给名为AC的属性,否则通过将其解析为Byte将值赋给AC.AC的类型是"Byte?" 在我的情况下,但它在上述作业中给出了错误.
无法确定条件表达式的类型,因为''和'byte'之间没有隐式转换C:\ Users\Waheed Ahmed\documents\visual studio 2010\Projects\Autos\Autos\Controllers\autosController.cs 274 85 Autos
我正在从Angular2发起一个发布请求到ASP.NET 5控制器操作.Angular正确发布数据并命中控制器操作,但它没有映射到控制器操作中定义的参数,参数是null.同时通过Request对象检查Request.Form具有正确的文本数据但不绑定到模型.
角
let body = JSON.stringify({ firstName: 'Ali' });
let headers = new Headers({ 'Content-Type': 'application/x-www-form-urlencoded' });
this.http.post(this.url, body, { headers: headers })
.subscribe(
(data) => {
console.log('Response received');
console.log(data);
},
(err) => { console.log('Error'); },
() => console.log('Authentication Complete')
);
Run Code Online (Sandbox Code Playgroud)
ASP.NET
[HttpPost]
public IActionResult DemoAction(string firstName)
{
var req = Request;
return null;
}
Run Code Online (Sandbox Code Playgroud)
Request.Form具有类似{\"firstName\":\"Ali\"}但参数firstName为的形式的数据null
strictNullChecks使用Angular 4.1.1 启用后,为null检查获取了多个错误.我有固定他们的包,但无法修复相同Object is possibly 'null'的this.form.get('username').value.与其他人一样,我尝试了同样但无法修复错误.
if (this.form.get('username') != null) {
body.append('username', this.form.get('username').value);
}
Run Code Online (Sandbox Code Playgroud) 我已经添加了自定义主题文件,并且希望在整个站点上减小字体大小。我不知道如何通过自定义主题更改字体大小,因为没有适当的文档。
@import '~@angular/material/theming';
// Plus imports for other components in your app.
// Include the common styles for Angular Material. We include this here so that you only
// have to load a single css file for Angular Material in your app.
// Be sure that you only ever include this mixin once!
@include mat-core();
// Define the palettes for your theme using the Material Design palettes available in palette.scss
// (imported above). For each palette, you can optionally specify …Run Code Online (Sandbox Code Playgroud) 我想为字符串添加验证规则,以与正则表达式模式中提供的任何字符串完全匹配。例如,status必须完全是“已批准”或“待定”,不能有其他内容。
'status' => 'required|regex:[???]'
Run Code Online (Sandbox Code Playgroud) command.Parameters.Add("@EndDate", SqlDbType.DateTime).Value =
EndDate == null ?
(DateTime?)null :
DateTime.Parse(EndDate.ToShortDateString() + " " + EndTime);
Run Code Online (Sandbox Code Playgroud)
EndDate的类型是DateTime?和EndTime只是一个包含时间的字符串.但它在解析时给我错误,因为EndDate是可以为空的DateTime.我怎么解析这个?
angular ×6
asp.net-core ×3
c# ×3
asp.net-mvc ×2
custom-theme ×2
datetime ×2
typescript ×2
exception ×1
forms ×1
laravel-5 ×1
mouseevent ×1
ngfor ×1
regex ×1
sass ×1
validation ×1