在模板中,我有一个表单,其中一部分与渲染课程列表有关:
<form #f="ngForm" (ngSubmit)="submit(f)">
<div class="form-group">
<label for="courseCategory"> Category </label>
<select required ngModel name="courseCategory" #courseCategory="ngModel" id="courseCategory" class="form-control">
<option value=""></option>
<option *ngFor="let category of categories" [value]="category.id"> // line 16
{{category.name}}
</option>
</select>
<div class="alert alert-danger" *ngIf="courseCategory.touched && courseCategory.errors.required">
Course category is required
</div>
</div>
</form>
Run Code Online (Sandbox Code Playgroud)
在浏览器中,当我选择一个类别并按TAB(离开下拉列表)时,我在控制台上收到此错误:
CourseComponent.html:16错误TypeError:无法在Object.eval [作为updateDirectives]读取属性'required'(CourseComponent.html:20)
你能帮我找出导致这个错误的原因吗?
Boot Code 3.3.7已安装在VS代码中.
我正在学习ASP.NET Core。我用于此目的的服务器是Postman,我将其从磁盘导入JSON文件。API的代码是用Visual Studio编写的,并且编译时没有错误。在邮递员中发送GET请求时,出现以下错误:“无法获得任何响应”。为了解决这个问题,我对设置进行了更改(请参见所附图像),但这不是解决方案。可以请我吗?

控制器的代码:
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace CityInfo.API.Controllers
{
[Route("api/cities")]
public class CitiesController : Controller
{
[HttpGet()]
public IActionResult GetCities()
{
return Ok(CitiesDataStore.Current.Cities);
}
[HttpGet("{id}")]
public IActionResult GetCity(int id)
{
var cityToReturn = CitiesDataStore.Current.Cities.FirstOrDefault(c => c.Id == id);
//);
if (cityToReturn == null)
return NotFound();
else
return Ok(cityToReturn);
}
}
}
Run Code Online (Sandbox Code Playgroud) 我有一个主页,用户在其中单击“ 联系我”以将其重定向到“ 联系”页面:
home.component.html
<div>
<a routerLink="/contact" [queryParams]="sendOBj">Contact me</a>
</div>
Run Code Online (Sandbox Code Playgroud)
home.component.ts:
import { Component, OnInit } from '@angular/core';
import { ActivatedRoute } from '../../../node_modules/@angular/router';
import { FollowersService } from '../followers.service';
@Component({
selector: 'app-home',
templateUrl: './home.component.html',
styleUrls: ['./home.component.css']
})
export class HomeComponent implements OnInit {
myfollowers: any[];
sendOBj: {id: any, name: any};
constructor(private followers: FollowersService, private route: ActivatedRoute) { }
ngOnInit() {
this.myfollowers = this.followers.getFollowers();
this.sendOBj = {id: this.myfollowers[0].id, name: this.myfollowers[0].name };
}
}
Run Code Online (Sandbox Code Playgroud)
contact.component.ts:
import { …Run Code Online (Sandbox Code Playgroud) 我有一个Angular应用程序.它的HTML文件包含一个div带有类的行,它本身包含两个div带有类的s col.通过单击按钮,列的大小会发生变化:
<button class="btn btn-primay" (click)="changeColumnsSize()"> change column sizes</button>
<div class="row">
<div id="leftColumn" class="col-sm-{{leftColumnSize}}" style="background-color:lavender;">
.col-sm-8
</div>
<div id ="rightColumn" *ngIf="this.state===true" class="col-sm-{{rightColumnSize}}" style="background-color:lavenderblush;">
.col-sm-4
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
为了平滑调整大小,我将过渡属性添加到CSS文件中的col类:
.col-sm-8 { transition: width .5s ease; }
.col-sm-4 { transition: width .5s ease ; }
Run Code Online (Sandbox Code Playgroud)
该TS文件(包含changeColumnsSize函数)看起来是这样的:
export class BoxComponent {
leftColumnSize: number = 12;
rightColumnSize: number = 0;
colDifference: number = 4;
state: boolean = false;
constructor() { …Run Code Online (Sandbox Code Playgroud)