在这里我为EName验证编写了一个小的验证属性,当我尝试2加载Html页面时,我将错误视为'ngClass',因为它不是'div'的已知属性.(
Component.ts
import { Component, OnInit } from "@angular/core"
import { Employee } from "../../../templates/employee/employee"
import { Validators, FormGroup, FormBuilder } from "@angular/forms"
@Component({
selector: "customer-ui",
templateUrl: "../../../templates/customer/customer.html"
})
export class JamComponent implements OnInit {
EmpleoyeeForm: FormGroup;
public constructor(private fb: FormBuilder) {}
ngOnInit(): void {
this.EmpleoyeeForm = this.fb.group({
EmpName: ['', [Validators.required]]
})
}
Run Code Online (Sandbox Code Playgroud)
Htmlcode
<form class="form-horizontal" novalidate [formGroup]="EmpleoyeeForm">
<fieldset>
<div class="form-group" [ngClass]="{'has-error': (EmpleoyeeForm.get('EmpName').touched ||
EmpleoyeeForm.get('EmpName').dirty) &&
!EmpleoyeeForm.get('EmpName').valid }">
<label for="name">Name</label>
<input type="text" class="form-control" formControlName="EmpName" [(ngModel)]="EmpName" />
</div>
</fieldset>
</form>
Run Code Online (Sandbox Code Playgroud) 我是建筑师的新手.请解释为什么它给我以下错误:
"An error occurred when trying to create a controller of type 'HomeController'. Make sure that the controller has a parameterless public constructor.
Run Code Online (Sandbox Code Playgroud)
这里我有1个接口(IRepo)1类文件(Repo)IRepo.cs
public interface IRepo
{
IEnumerable<Employee> GetEmployee();
IQueryable<Employee> GetEmployee(int id);
}
Run Code Online (Sandbox Code Playgroud)
Repo.cs
Ctxdb _db = null;
public Repo(Ctxdb db)
{
this._db = db;
}
public IEnumerable<Employee> GetEmployee()
{
//
}
Run Code Online (Sandbox Code Playgroud)
HomeController.cs
IRepo _ObjRepo = null;
public HomeController(Repo ObjRepo)
{
_ObjRepo = ObjRepo;
}
[Route("GetEmp")]
[HttpGet]
public IHttpActionResult GetDat()
{
var x = _ObjRepo.GetEmployee();
if (x != null) …Run Code Online (Sandbox Code Playgroud)