小编Mic*_*nko的帖子

属性'...'没有初始化程序,并且在构造函数中没有明确赋值

在我的Angular应用程序中,我有一个组件:

import { MakeService } from './../../services/make.service';
import { Component, OnInit } from '@angular/core';

@Component({
  selector: 'app-vehicle-form',
  templateUrl: './vehicle-form.component.html',
  styleUrls: ['./vehicle-form.component.css']
})
export class VehicleFormComponent implements OnInit {
  makes: any[];
  vehicle = {};

  constructor(private makeService: MakeService) { }

  ngOnInit() {
    this.makeService.getMakes().subscribe(makes => { this.makes = makes
      console.log("MAKES", this.makes);
    });
  }

  onMakeChange(){
    console.log("VEHICLE", this.vehicle);
  }
}
Run Code Online (Sandbox Code Playgroud)

但在"制造"属性中我有一个错误.我不知道该怎么做...

错误

javascript typescript angular

45
推荐指数
26
解决办法
2万
查看次数

反应路由实施

我正在尝试在我的React应用程序中实现路由。所以我有一个可以导航到另一个组件的组件:

  class Order extends Component {

        render() {

            return (
                <div>
                     <ul>
                       <li>
                         <Link to="/stepOne/">1</Link>
                        </li>
                       <li>
                        <Link to="/stepTwo/">2</Link>
                       </li>
                          <Link to="/stepThree/">3</Link>
                        <li>
                           <Link to="/steFour/">4</Link>
                        </li>
                     </ul>

                    <Switch>
                        <Route exact path="/stepOne" component={SearchConcoctionFormula} />
                        <Route exact path="/stepTwo" component={OrderStepTwoIndex} />
                        <Route exact path="/stepThree" component={OrderStepThreeIndex} />
                        <Route exact path="/stepFour" component={OrderStepFourIndex} />
                    </Switch>
                </div>);
        }
    }

    export default Order;
Run Code Online (Sandbox Code Playgroud)

但是我的问题是,当我单击链接时,所选组件随导航链接一起呈现。但我希望仅渲染选定的组件。我应该改变什么?

routing reactjs react-native

3
推荐指数
1
解决办法
37
查看次数

按嵌套集合的 LINQ 过滤器列表

我有以下类层次结构:

public class SportPlan
{
    public Guid Id { get; set; }
    public string Name { get; set; }
    public List<Record> RecordFields { get; set; }
}

public class Record
{
    public Guid Key { get; set; }
    public string Alias { get; set; }
    public List<Value> Values { get; set; }
}

public class Value
{
    public int Index { get; set; }
    public List<DayOfWeek> DaysOfWeek { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

我需要SportPlan.RecordFieldsdayOfWeek(.NET enum)过滤并Value使用 …

c# linq

2
推荐指数
1
解决办法
91
查看次数

c#日期时间。将时间重置为 0

我有 dateTime =3/25/2020 1:25:46 PM 我可以将时间重置为零吗?3/25/2020 00:00:00

这是一个演示。在这种情况下,日期时间是3/25/2020 12:00:00 AM

class Program
{
    static  void Main(string[] args)
    {

        var datetime = DateTime.Now;
        datetime = ResetTimeToStartOfDay(datetime);

        Console.WriteLine(datetime);
        Console.ReadLine();
    }

    public static DateTime ResetTimeToStartOfDay(DateTime dateTime)
    {
        return new DateTime(
           dateTime.Year,
           dateTime.Month,
           dateTime.Day,
           0, 0, 0, 0);
    }
}
Run Code Online (Sandbox Code Playgroud)

如何将日期重置为一天的开始?

c# datetime

2
推荐指数
1
解决办法
611
查看次数

ASP.NET MVC中的UnitOfWork错误

我在mvc5项目中使用UnitOfWork模式。

我有一个带有服务的BLL层。

 public class StudentService
    {
        private readonly IUnitOfWork _db;

        public StudentService(IUnitOfWork uow)
        {
            _db = uow;
        }

        public IEnumerable<StudentView> GetStudentViews()
        {
            List<Student> students = _db.Students.GetAll().ToList();
            return Mapper.Map<List<Student>, List<StudentView>>(students);
        }
}
Run Code Online (Sandbox Code Playgroud)

但是,当我尝试在mvc控制器中使用此服务时,出现错误:“没有为此对象定义无参数构造函数。”

public class StudentController : Controller
    {
        private readonly StudentService _service;

        public StudentController(StudentService service)
        {
            _service = service;
        }

        // GET: Student
        public ActionResult Index()
        {
            IEnumerable<StudentView> studentViews = _service.GetStudentViews();
            return View("Index", studentViews);
        }
}
Run Code Online (Sandbox Code Playgroud)

我没有无参数构造函数,但是如何在控制器中将我的服务与无参数构造函数一起使用?

我将DI用于UnitOf工作:

 public class ServiceModule : NinjectModule
    {
        private string connection;
        public ServiceModule(string connection) …
Run Code Online (Sandbox Code Playgroud)

c# asp.net asp.net-mvc unit-of-work

0
推荐指数
1
解决办法
80
查看次数

AutoMapper - 将模型映射到字典

我正在尝试使用 AutoMapper 映射 DTO Dictionary<string, object>

public class SetEmr
{
    public string Name { get; set; }
    public int Repeat { get; set; }
    public int RestTime { get; set; }
    public int Order { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

我正在尝试做这样的事情:

CreateMap<SetEmr, Dictionary<string, object>>()
    .ForMember(dest => dest, opt => opt.MapFrom((src, dst, _, context) =>
    {
        return new Dictionary<string, object>
        {
            { "Name", src.Name },
            { "Repeat", src.Repeat},
            { "Order", src.Order}
        };
    }));
Run Code Online (Sandbox Code Playgroud)

这不起作用。

“只有类型上的顶级个人成员才支持成员的自定义配置。”

还有其他方法可以实现这样的映射吗?

c# automapper

0
推荐指数
1
解决办法
873
查看次数