我正在使用angular开发aspnetzero应用程序,但是当我在p-dataTable中分配categories属性值时,我在浏览器控制台中收到此错误:
无法绑定到'value',因为它不是'p-dataTable'的已知属性
我有三个文件.第一个文件categories.component.ts
import { Component, Injector, OnInit } from '@angular/core';
import { AppComponentBase } from '@shared/common/app-component-base';
import { appModuleAnimation } from '@shared/animations/routerTransition';
import { Http, Response, Headers, RequestOptions } from "@angular/http";
import { AppSessionService } from '@shared/common/session/app-session.service';
import { Category } from './category';
import { DataTableModule, SharedModule, DataTable } from 'primeng/primeng';
@Component({
templateUrl: './categories.component.html',
animations: [appModuleAnimation()]
})
export class CategoriesComponent extends AppComponentBase implements OnInit {
categories: Category[];
constructor(
injector: Injector,
private http: Http,
private appSessionService: AppSessionService
) {
super(injector); …Run Code Online (Sandbox Code Playgroud) 我有以下 Typescript 布尔函数:
checkRiskValues(): boolean {
this.controlsName.forEach((item) => {
this.threatForm.get(item)!.valueChanges.subscribe(value => {
this.valueControlArray.push(this.threatForm.get(item)!.value);
if (this.valueControlArray.indexOf(true) > -1)
return true;
else
return false
});
});
}
Run Code Online (Sandbox Code Playgroud)
该方法出现错误,函数必须返回值。我知道,但我不确定如何在 foreach 范围之外实现这个 true/false 语句?
如果我在 foreach 循环之外调用 if/else 语句,结果总是 false,因为
if (this.valueControlArray.indexOf(true) > -1)
Run Code Online (Sandbox Code Playgroud)
是空的..
编辑
我删除了 checkRiskValues() 函数并在 ngOnInit() 方法中添加了完整的逻辑,并且还添加了 valueControl 变量来保留 true/false 值并传入另一个函数。谢谢大家..这是我的解决方案:
ngOnInit() {
this.controlsName.forEach((item) => {
this.threatForm.get(item)!.valueChanges.subscribe(value => {
this.valueControlArray.push(this.threatForm.get(item)!.value);
if (this.valueControlArray.indexOf(true) > -1) {
this.valueControl = true;
}
else {
this.valueControl = false;
}
});
});
}
Run Code Online (Sandbox Code Playgroud) 我在控制器中有异步方法,可以从客户端调用该方法。我想在 foreach 循环中迭代此方法,但出现错误:
*Cannot convert from 'Microsoft.AspNetCore.Mvc.ActionResult' to 'System.Collections.Generic.IEnumerable<string>'*
Run Code Online (Sandbox Code Playgroud)
单元测试.cs
[TestFixture]
public class ClientUnitTests
{
private MessagesController Controller = new MessagesController(null, null, null);
[Test]
public async Task Check_API_Links()
{
// Arrange
List<IEnumerable<string>> reporteeList = new List<IEnumerable<string>>();
var links = await Controller.GetLinks();
reporteeList.Add(links); //Cannot convert from 'Microsoft.AspNetCore.Mvc.ActionResult' to 'System.Collections.Generic.IEnumerable<string>'
foreach (var itemLink in reporteeList)
{
reporteeList.Add(itemLink);
}
// Assert
Assert.IsNotNull(reporteeList);
Assert.GreaterOrEqual(0, reporteeList.Count);
Assert.IsInstanceOf<IEnumerable<string>>(reporteeList);
}
}
Run Code Online (Sandbox Code Playgroud)
控制器.cs
[HttpGet]
public async Task<ActionResult> GetLinks()
{
var result = await _client.GetLinks();
return Ok(result);
}
Run Code Online (Sandbox Code Playgroud)
客户端.cs …
我需要在HttpClientFactory中添加证书.老实现HttpClient看看这个:
var cookieContainer = new CookieContainer();
var handler = new HttpClientHandler { CookieContainer = cookieContainer };
var basePath = Directory.GetCurrentDirectory();
var certificatePath = Path.Combine(basePath, certPath);
var fileExists = File.Exists(certificatePath);
if (!fileExists)
throw new ArgumentException(certificatePath);
var certificate = new X509Certificate2(certificatePath, certPwd);
handler.ClientCertificates.Add(certificate);
using (var client = new HttpClient(handler))
{
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(accept));
client.DefaultRequestHeaders.Add("ApiKey", apiKey);
var body = new { UserName = username, UserPassword = password };
var jsonBody = JsonConvert.SerializeObject(body);
var content = new StringContent(jsonBody, Encoding.UTF8, contentType);
var …Run Code Online (Sandbox Code Playgroud) 我使用物料清单控件显示嵌套对象。我用div创建了垫子列表,但是我想在此处添加“展开/折叠行”选项,当我单击行时,它应该显示子类别div?
<mat-list>
<div *ngFor="let item of chaptersItems">
<mat-list-item>
<a style="cursor: pointer;">
<h4 mat-line>{{item.name}} {{item.description}}</h4>
</a>
</mat-list-item>
<mat-list style="margin-left:30px;">
<div *ngFor="let subItem of item.subChapters">
<mat-list-item>
<a style="cursor: pointer;">
<p mat-line> {{subItem.name}}. {{subItem.description}}</p>
</a>
</mat-list-item>
</div>
</mat-list>
</div>
</mat-list>
Run Code Online (Sandbox Code Playgroud)
如何在div或mat-list控件上实现click功能?
我有 Angular 组件,它可以渲染一些数据并有按钮 Go to Dashboard,但我有两个选项可以移动到下一页。第一个如果用户在 10 秒后没有点击按钮 GoDashobard 应用程序会自动将他切换到该链接。
但是,如果用户仍然单击此按钮并转到下一个链接,则会在 10 秒后再次触发超时,并返回到该页面或刷新(如果已经在该页面上)。
我试图通过 isClickGoToDashboard 解决它,但它再次调用,可能是因为它在第一次之后加载到 ngOnInit () 上。
单击按钮不计算计数器并再次调用后,如何撤消此操作?
ngOnInit(): void {
if (!this.isClickGoToDashboard) {
setTimeout(() => {
this.router.navigateByUrl('home');
}, 10000);
}
}
goToDashboard() {
this.isClickGoToDashboard = true;
this.router.navigateByUrl('home');
}
Run Code Online (Sandbox Code Playgroud)