有没有人成功地使用mat-selection-list过 Angular 的反应式形式。当我尝试使用它时,我得到了
values.map 不是函数
下面是我的 html 代码:
<div class="form-group" [formGroup]="activityForm">
<mat-selection-list formControlName="activity" (selectionChange)="onActivitySelected($event)">
<mat-list-option *ngFor="let act of activities"
[value]="act.id">
{{act.name}}
</mat-list-option>
</mat-selection-list>
</div>
Run Code Online (Sandbox Code Playgroud)
这是我的表单定义:
this.formGroup1 = this.fb.group({
destinationForm: this.fb.group({
destination: [null, Validators.required]
}),
activityForm: this.fb.group({
activity: [[''], Validators.required]
}),
travellerForm: this.fb.group({
firstName: ['', Validators.required],
lastName: '',
})
});
Run Code Online (Sandbox Code Playgroud)
有人可以帮忙解决这个问题吗
我的其中一个属性如下所示:
public string Name
{
get{ return _name; }
set { _name = value; }
}
Run Code Online (Sandbox Code Playgroud)
但是ReSharper建议我将其更改为:
public string Name
{
get => _name;
set => _name = value;
}
Run Code Online (Sandbox Code Playgroud)
如果我这样重构,则编译会引发错误是否无法在Property中包含表达式主体?
我在我的 api 控制器类之一中使用以下 DTO 类,在一个 asp.net 核心应用程序中。
public class InviteNewUserDto: IValidatableObject
{
private readonly IClientRepository _clientRepository;
public InviteNewUserDto(IClientRepository clientRepository)
{
_clientRepository = clientRepository;
}
//...code omitted for brevity
}
Run Code Online (Sandbox Code Playgroud)
这就是我在控制器中使用它的方式
[HttpPost]
public async Task<IActionResult> RegisterUser([FromBody] InviteNewUserDto model)
{
if (!ModelState.IsValid) return BadRequest(ModelState);
//...omitted for brevity
}
Run Code Online (Sandbox Code Playgroud)
但是我System.NullReferenceException在 DTO 类中得到了一个这是因为依赖注入在 DTO 类中不起作用。我怎样才能解决这个问题 ?
dependency-injection model-validation ivalidatableobject asp.net-core
在 swift 4 中,您可以使用以下方法提取子字符串:
let str = "abcdefghci"
let index = str.index(of: "c") ?? str.endIndex
print(str[...index])
Run Code Online (Sandbox Code Playgroud)
这将打印 abc
但是我怎样才能找到最后一个的索引,c从那个位置提取一个子字符串呢?
更新
@vadian 请看附图:
jasmine-marbles我正在尝试使用但出现错误进行简单的测试
这是我的测试代码:
describe('MarbleTestingComponent', () => {
it('should test marble syntax', () => {
const provided = search('e');
const expected = cold('(e|)', {e: 'e'});
console.log(expected, provided);
expect(provided).toBeObservable(expected);
})
});
Run Code Online (Sandbox Code Playgroud)
这是我收到的错误:
Error:
Expected: (e|),
Received: (?|),
Expected:
[{"frame":0,"notification":{"kind":"N","value":"e","hasValue":true}},{"frame":0,"notification":{"kind":"C","hasValue":false}}]
Received:
[{"frame":0,"notification":{"kind":"N","value":"e"}},{"frame":0,"notification":{"kind":"C"}}],
Run Code Online (Sandbox Code Playgroud)
如果我使用该jest框架,上面的代码可以工作,但我想让它与 Angular 设置附带的默认测试框架一起工作
感谢您对解决此错误的任何帮助,谢谢