我有一个问题,我如何从两个实体发帖。我说我已创建类别现在发布我想使用类别帖子作为下拉菜单,然后通过从角度2/4中的数据库中提取类别来发布产品。我将不胜感激任何帮助。先感谢您。请看下面我遇到的问题
我的服务
if(Test-Path HKLM:\SOFTWARE\ODBC\ODBC.INI\user){
Set-Location HKLM:\SOFTWARE\ODBC\ODBC.INI\user
$server = (Get-ItemProperty HKLM:\SOFTWARE\ODBC\ODBC.INI\user).SERVER
if($server-eq "user"){
Set-ItemProperty . SERVER "user.app"
"Set1"}
}
if(Test-Path HKLM:\SOFTWARE\Wow6432Node\ODBC\ODBC.INI\user){
Set-Location HKLM:\SOFTWARE\Wow6432Node\ODBC\ODBC.INI\user
$server = (Get-ItemProperty HKLM:\SOFTWARE\Wow6432Node\ODBC\ODBC.INI\user).SERVER
if($server-eq "user"){
Set-ItemProperty . SERVER "user.app"
"Set2"}
}
下面是我尝试通过预先填充具有id,类别类型为字段的类别中的某些字段来创建产品的组件 产品组件
import { Injectable } from '@angular/core';
import { Http, Headers, RequestOptions, Response} from '@angular/http';
import 'rxjs/add/operator/map';
import 'rxjs/add/observable/throw';
import { Observable } from 'rxjs/Observable';
@Injectable()
export class myService {
addProduct(prod){
const body = JSON.stringify(prod);
const headers = new Headers({'Content-Type': 'application/json'});
let Url= "https://localhost/v1/products";
return this.http.post(Url, body, {headers: headers}).map(res=>res.json())
}
addCat(cat){
const body = JSON.stringify(cat);
const headers = new Headers({'Content-Type': 'application/json'});
let catUrl= "https://localhost/v1/cat";
return this.http.post(Url, body, {headers: headers}).map(res=>res.json())
}
getCat(){
this.http.get(catUrl).map(res => res.json())
}
}
html内容就是这个
import { Component, OnInit } from '@angular/core';
import {MyService} from '../myservice';
@Component({
selector: 'app-report',
templateUrl: './product.component.html',
styleUrls: ['./product.component.css']
})
export class ProductComponent implements OnInit {
cat: any = [];
proName: any;
proPrice: any;
constructor(){}
ngOnInit(){
this.cat = this.myService.getCat().subscribe(rescat => this.cat = rescat)
}
addProduct(){
let produc ={
name: this.proName,
price: this.proPrice,
catType: this.cat.name,
catId : this.cat.id
}
this.myService.addProduct(produc).subscribe(data =>
console.log(data))
}
}
我不确定如何在产品创建中包含该类别,我们将不胜感激