Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-core/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
asp.net core angular和ng2智能表从数据库获取数据_Angular_Asp.net Core - Fatal编程技术网

asp.net core angular和ng2智能表从数据库获取数据

asp.net core angular和ng2智能表从数据库获取数据,angular,asp.net-core,Angular,Asp.net Core,朋友们。我刚开始学习asp.net核心和angular。我使用角度6。我想使用ng2智能表从mssql数据库输出一个表。如何编写数据和CRUD操作的输出函数。请帮帮我 我的代码 它是我的控制器 using System.Collections.Generic; using System.Linq; using Microsoft.AspNetCore.Mvc; using WebApplication12.Models; namespace WebApplication12.Controlle

朋友们。我刚开始学习asp.net核心和angular。我使用角度6。我想使用ng2智能表从mssql数据库输出一个表。如何编写数据和CRUD操作的输出函数。请帮帮我

我的代码

它是我的控制器

using System.Collections.Generic;
using System.Linq;
using Microsoft.AspNetCore.Mvc;
using WebApplication12.Models;

namespace WebApplication12.Controllers
{
    [Route("api/otchets")]
    public class OtchetController : Controller
    {
        web_celContext db;

        public OtchetController(web_celContext context)
        {
            db = context;

        }
        [HttpGet]
        public IEnumerable<Otchet> Get()
        {
            return db.Otchet.ToList();
        }

        [HttpGet("{id}")]
        public Otchet Get(int id)
        {
            Otchet otchet = db.Otchet.FirstOrDefault(x => x.Id == id);
            return otchet;
        }




        [HttpPost]
        public IActionResult Post([FromBody]Otchet otchet)
        {
            if (ModelState.IsValid)
            {
                db.Otchet.Add(otchet);
                db.SaveChanges();
                return Ok(otchet);
            }
            return BadRequest(ModelState);
        }

        [HttpPut("{id}")]
        public IActionResult Put(int id, [FromBody]Otchet otchet)
        {
            if (ModelState.IsValid)
            {
                db.Update(otchet);
                db.SaveChanges();
                return Ok(otchet);
            }
            return BadRequest(ModelState);
        }

        [HttpDelete("{id}")]
        public IActionResult Delete(int id)
        {
            Otchet otchet = db.Otchet.FirstOrDefault(x => x.Id == id);
            if (otchet != null)
            {
                db.Otchet.Remove(otchet);
                db.SaveChanges();
            }
            return Ok(otchet);
        }
    }
}
这是home1.ts

using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Threading.Tasks;

namespace WebApplication12.Models
{
    public class Otchet
    {
        public int Id { get; set; }
        public string Doljnost { get; set; }

        public string Familiya { get; set; }
        public string Imya { get; set; }
        public string Onchestvo { get; set; }
        public string Veha { get; set; }
        public decimal Ves { get; set; }

        public string Fact { get; set; }

    }
}
export class Otchet {
  constructor(
    public id?: number,
    public Doljnost?: string,
    public Familiya?: string,
    public Imya?: string,
    public Onchestvo?: string,
    public Veha?: string,
    public Fact?: string,  
    public Ves?: number) { }
}
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Otchet } from './home1';

@Injectable()
export class DataService {

  private url = "/api/otchets";

  constructor(private http: HttpClient) {
  }

  getOtchets() {
    return this.http.get(this.url);
  }


  createOtchet(otchet: Otchet) {
    return this.http.post(this.url, otchet);
  }



 updateOtchet(otchet: Otchet) {

    return this.http.put(this.url + '/' + otchet.id, otchet);
  }

  deleteOtchet(id: number) {
    return this.http.delete(this.url + '/' + id);
  }
}
import { Component, OnInit } from '@angular/core';
import { Otchet } from './home1';
import { DataService } from './data.service';

@Component({
  selector: 'app-home1',
  templateUrl: './home1.component.html',
  providers: [DataService]
})

export class Home1Component implements OnInit {

  otchet: Otchet = new Otchet();   // изменяемый товар
  otchets: Otchet[];
  //tableMode: boolean = true;   

  settings = {
    columns: {
      id: {
        title: 'id',
      },

      Ves: {
        title: 'Ves',
      },

    },
  };

  constructor(private dataService: DataService) { }

  ngOnInit() {
    this.loadOtchets(); 

  }

  loadOtchets() {
    this.dataService.getOtchets()
      .subscribe((data: Otchet[]) => this.otchets = data);
  }
}
它是data.service.ts

using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Threading.Tasks;

namespace WebApplication12.Models
{
    public class Otchet
    {
        public int Id { get; set; }
        public string Doljnost { get; set; }

        public string Familiya { get; set; }
        public string Imya { get; set; }
        public string Onchestvo { get; set; }
        public string Veha { get; set; }
        public decimal Ves { get; set; }

        public string Fact { get; set; }

    }
}
export class Otchet {
  constructor(
    public id?: number,
    public Doljnost?: string,
    public Familiya?: string,
    public Imya?: string,
    public Onchestvo?: string,
    public Veha?: string,
    public Fact?: string,  
    public Ves?: number) { }
}
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Otchet } from './home1';

@Injectable()
export class DataService {

  private url = "/api/otchets";

  constructor(private http: HttpClient) {
  }

  getOtchets() {
    return this.http.get(this.url);
  }


  createOtchet(otchet: Otchet) {
    return this.http.post(this.url, otchet);
  }



 updateOtchet(otchet: Otchet) {

    return this.http.put(this.url + '/' + otchet.id, otchet);
  }

  deleteOtchet(id: number) {
    return this.http.delete(this.url + '/' + id);
  }
}
import { Component, OnInit } from '@angular/core';
import { Otchet } from './home1';
import { DataService } from './data.service';

@Component({
  selector: 'app-home1',
  templateUrl: './home1.component.html',
  providers: [DataService]
})

export class Home1Component implements OnInit {

  otchet: Otchet = new Otchet();   // изменяемый товар
  otchets: Otchet[];
  //tableMode: boolean = true;   

  settings = {
    columns: {
      id: {
        title: 'id',
      },

      Ves: {
        title: 'Ves',
      },

    },
  };

  constructor(private dataService: DataService) { }

  ngOnInit() {
    this.loadOtchets(); 

  }

  loadOtchets() {
    this.dataService.getOtchets()
      .subscribe((data: Otchet[]) => this.otchets = data);
  }
}
它是home1.component.ts

using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Threading.Tasks;

namespace WebApplication12.Models
{
    public class Otchet
    {
        public int Id { get; set; }
        public string Doljnost { get; set; }

        public string Familiya { get; set; }
        public string Imya { get; set; }
        public string Onchestvo { get; set; }
        public string Veha { get; set; }
        public decimal Ves { get; set; }

        public string Fact { get; set; }

    }
}
export class Otchet {
  constructor(
    public id?: number,
    public Doljnost?: string,
    public Familiya?: string,
    public Imya?: string,
    public Onchestvo?: string,
    public Veha?: string,
    public Fact?: string,  
    public Ves?: number) { }
}
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Otchet } from './home1';

@Injectable()
export class DataService {

  private url = "/api/otchets";

  constructor(private http: HttpClient) {
  }

  getOtchets() {
    return this.http.get(this.url);
  }


  createOtchet(otchet: Otchet) {
    return this.http.post(this.url, otchet);
  }



 updateOtchet(otchet: Otchet) {

    return this.http.put(this.url + '/' + otchet.id, otchet);
  }

  deleteOtchet(id: number) {
    return this.http.delete(this.url + '/' + id);
  }
}
import { Component, OnInit } from '@angular/core';
import { Otchet } from './home1';
import { DataService } from './data.service';

@Component({
  selector: 'app-home1',
  templateUrl: './home1.component.html',
  providers: [DataService]
})

export class Home1Component implements OnInit {

  otchet: Otchet = new Otchet();   // изменяемый товар
  otchets: Otchet[];
  //tableMode: boolean = true;   

  settings = {
    columns: {
      id: {
        title: 'id',
      },

      Ves: {
        title: 'Ves',
      },

    },
  };

  constructor(private dataService: DataService) { }

  ngOnInit() {
    this.loadOtchets(); 

  }

  loadOtchets() {
    this.dataService.getOtchets()
      .subscribe((data: Otchet[]) => this.otchets = data);
  }
}
它是home1.component.html

<ng2-smart-table [settings]="settings" [source]="otchets"></ng2-smart-table>


请帮帮我。

有人知道答案吗?有人知道答案吗?