Javascript Firebase以选择的形式显示数据-角度
我试图以选择的形式显示数据,从表英雄和“nombre” 这是客户端的名称 在我的第二个表中,我想在向中添加产品时显示它们 将客户归于他们 有人能帮我吗?我是新来的:) heromes.component.tsJavascript Firebase以选择的形式显示数据-角度,javascript,angular,firebase,firebase-realtime-database,Javascript,Angular,Firebase,Firebase Realtime Database,我试图以选择的形式显示数据,从表英雄和“nombre” 这是客户端的名称 在我的第二个表中,我想在向中添加产品时显示它们 将客户归于他们 有人能帮我吗?我是新来的:) heromes.component.ts import { Component, OnInit } from '@angular/core'; import { HeroesService } from '../../services/heroes.service'; import { HeroeModel } from '.
import { Component, OnInit } from '@angular/core';
import { HeroesService } from '../../services/heroes.service';
import { HeroeModel } from '../../models/heroe.model';
import {AngularFireDatabase } from 'angularfire2/database';
import Swal from 'sweetalert2';
@Component({
selector: 'app-heroes',
templateUrl: './heroes.component.html',
styleUrls: ['./heroes.component.css']
})
export class HeroesComponent implements OnInit {
heroes: HeroeModel[] = [];
cargando = false;
constructor(private heroesService: HeroesService) {}
ngOnInit() {
this.cargando = true;
this.heroesService.getHeroes().subscribe(resp => {
this.heroes = resp;
this.cargando = false;
});
}
borrarHeroe(heroe: HeroeModel, index: number) {
Swal.fire({
title: 'Uwaga!',
text: `Czy chcesz trwale usunąć kontrahenta ${heroe.nombre}?`,
type: 'warning',
showConfirmButton: true,
showCancelButton: true
}).then(resp => {
if (resp.value) {
this.heroesService.deleteHeroe(heroe.id).subscribe(resp => {
this.heroes.splice(index, 1);
});
}
});
}
}
import { Component, OnInit } from '@angular/core';
import { NgForm } from '@angular/forms';
import Swal from 'sweetalert2';
import { Observable } from 'rxjs';
import { ActivatedRoute } from '@angular/router';
import { ADDProductsModel } from 'src/app/models/add-products.model';
import { ProductsService } from 'src/app/services/products.service';
import { HeroesComponent } from 'src/app/pages/heroes/heroes.component';
import { HeroeComponent } from 'src/app/pages/heroe/heroe.component';
@Component({
selector: 'app-add-products',
templateUrl: './add-products.component.html',
styleUrls: ['./add-products.component.css']
})
export class ADDProductsComponent implements OnInit {
ADDProducts: ADDProductsModel = new ADDProductsModel();
constructor(
private ProductsService: ProductsService,
private route: ActivatedRoute
) {}
ngOnInit() {
const id = this.route.snapshot.paramMap.get('id');
if (id !== 'new') {
this.ProductsService.getADDProducts(id).subscribe((resp: ADDProductsModel) => {
this.ADDProducts = resp;
this.ADDProducts.id = id;
});
}
}
guardar(form: NgForm) {
if (form.invalid) {
console.log('Nieprawidłowy format');
return;
}
Swal.fire({
title: 'Ładowanie',
text: 'Trwa zapis...',
type: 'info',
allowOutsideClick: false
});
Swal.showLoading();
let peticion: Observable<any>;
if (this.ADDProducts.id) {
peticion = this.ProductsService.actualizarADDProducts(this.ADDProducts);
} else {
peticion = this.ProductsService.crearADDProducts(this.ADDProducts);
}
peticion.subscribe(resp => {
Swal.fire({
title: this.ADDProducts.number,
text: 'Dodano pomyślnie',
type: 'success'
});
});
console.log(form);
console.log(this.ADDProducts);
}
}
add-products.component.ts
import { Component, OnInit } from '@angular/core';
import { HeroesService } from '../../services/heroes.service';
import { HeroeModel } from '../../models/heroe.model';
import {AngularFireDatabase } from 'angularfire2/database';
import Swal from 'sweetalert2';
@Component({
selector: 'app-heroes',
templateUrl: './heroes.component.html',
styleUrls: ['./heroes.component.css']
})
export class HeroesComponent implements OnInit {
heroes: HeroeModel[] = [];
cargando = false;
constructor(private heroesService: HeroesService) {}
ngOnInit() {
this.cargando = true;
this.heroesService.getHeroes().subscribe(resp => {
this.heroes = resp;
this.cargando = false;
});
}
borrarHeroe(heroe: HeroeModel, index: number) {
Swal.fire({
title: 'Uwaga!',
text: `Czy chcesz trwale usunąć kontrahenta ${heroe.nombre}?`,
type: 'warning',
showConfirmButton: true,
showCancelButton: true
}).then(resp => {
if (resp.value) {
this.heroesService.deleteHeroe(heroe.id).subscribe(resp => {
this.heroes.splice(index, 1);
});
}
});
}
}
import { Component, OnInit } from '@angular/core';
import { NgForm } from '@angular/forms';
import Swal from 'sweetalert2';
import { Observable } from 'rxjs';
import { ActivatedRoute } from '@angular/router';
import { ADDProductsModel } from 'src/app/models/add-products.model';
import { ProductsService } from 'src/app/services/products.service';
import { HeroesComponent } from 'src/app/pages/heroes/heroes.component';
import { HeroeComponent } from 'src/app/pages/heroe/heroe.component';
@Component({
selector: 'app-add-products',
templateUrl: './add-products.component.html',
styleUrls: ['./add-products.component.css']
})
export class ADDProductsComponent implements OnInit {
ADDProducts: ADDProductsModel = new ADDProductsModel();
constructor(
private ProductsService: ProductsService,
private route: ActivatedRoute
) {}
ngOnInit() {
const id = this.route.snapshot.paramMap.get('id');
if (id !== 'new') {
this.ProductsService.getADDProducts(id).subscribe((resp: ADDProductsModel) => {
this.ADDProducts = resp;
this.ADDProducts.id = id;
});
}
}
guardar(form: NgForm) {
if (form.invalid) {
console.log('Nieprawidłowy format');
return;
}
Swal.fire({
title: 'Ładowanie',
text: 'Trwa zapis...',
type: 'info',
allowOutsideClick: false
});
Swal.showLoading();
let peticion: Observable<any>;
if (this.ADDProducts.id) {
peticion = this.ProductsService.actualizarADDProducts(this.ADDProducts);
} else {
peticion = this.ProductsService.crearADDProducts(this.ADDProducts);
}
peticion.subscribe(resp => {
Swal.fire({
title: this.ADDProducts.number,
text: 'Dodano pomyślnie',
type: 'success'
});
});
console.log(form);
console.log(this.ADDProducts);
}
}
从'@angular/core'导入{Component,OnInit};
从'@angular/forms'导入{NgForm};
从“sweetalert2”进口棉签;
从“rxjs”导入{Observable};
从'@angular/router'导入{ActivatedRoute};
从'src/app/models/add products.model'导入{ADDProductsModel};
从'src/app/services/products.service'导入{ProductsService};
从'src/app/pages/heromes/heromes.component'导入{HeroesComponent};
从'src/app/pages/heroe/heroe.component'导入{heroComponent};
@组成部分({
选择器:“应用程序添加产品”,
templateUrl:“./add products.component.html”,
样式URL:['./添加产品.component.css']
})
导出类ADDProductsComponent实现OnInit{
ADDProducts:ADDProductsModel=新的ADDProductsModel();
建造师(
私人产品服务:产品服务,
专用路由:ActivatedRoute
) {}
恩戈尼尼特(){
const id=this.route.snapshot.paramMap.get('id');
如果(id!=“新建”){
this.ProductsService.getADDProducts(id).subscribe((resp:ADDProductsModel)=>{
this.ADDProducts=resp;
this.ADDProducts.id=id;
});
}
}
瓜达尔(表格:NgForm){
如果(格式无效){
log('Nieprawidłowy格式');
返回;
}
喷火({
标题:“Ładowanie”,
文字:“Trwa zapis…”,
键入:“info”,
allowOutsideClick:false
});
Swal.showLoading();
让佩蒂西奥:可观察;
if(this.ADDProducts.id){
peticion=this.ProductsService.RealizarAddProducts(this.ADDProducts);
}否则{
peticion=this.ProductsService.crearADDProducts(this.ADDProducts);
}
订阅(resp=>{
喷火({
标题:this.ADDProducts.number,
文字:“Dodano pomyślnie”,
类型:“成功”
});
});
控制台日志(表格);
console.log(this.ADDProducts);
}
}
- app.component.html
<div> <span > Name comes form child in Parent Component </span> <select> <option> Select Name </option> <option *ngFor="let item of nameFromChild"> {{item}} </option> </select> </div>
<input type ="text" [(ngModel)]="name"> <br><br> <button (click)="sendNameToParent(name)"> Add Name to Parent </button>
- child.component.html
<div> <span > Name comes form child in Parent Component </span> <select> <option> Select Name </option> <option *ngFor="let item of nameFromChild"> {{item}} </option> </select> </div>
<input type ="text" [(ngModel)]="name"> <br><br> <button (click)="sendNameToParent(name)"> Add Name to Parent </button>
将名称添加到父级 - 子组件.ts
export class AppComponent { nameFromChild: string[] = []; // your property. /* nameFromChildFun() is called when there is data emitted from child-component. @parms ='nameFromChild' : gets parameter from child using $event from app.component.html. */ nameFromChildFun(nameFromChild){ this.nameFromChild.push(nameFromChild); //name pushes to property. and displaying in select tag using *ngFor. } }
import { Component, EventEmitter, Output } from '@angular/core'; export class ChildComponent implements OnInit { @Output() nameFromChild = new EventEmitter(); // nameFromChild is passed in app.component.html in <app-child (nameFromChild)="nameFromChildFun($event) sendNameToParent(name){ this.nameFromChild.emit(name); // emitting value to parent. } }
从'@angular/core'导入{Component,EventEmitter,Output}; 导出类ChildComponent实现OnInit{ @Output()nameFromChild=neweventemitter();
//nameFromChild在app.component.html中传递,有什么问题?我不知道如何下载数据以将表单填充到另一个组件:(我已经尝试处理这个问题好几个小时了。您可以使用
和@input
指令进行组件交互。您可以使用@output
将数据发送到子组件,从子组件发送到父组件,您可以使用@input
发送事件emmiter。或者,您也可以使用rxJS Subject..在您的情况下,yo你可以考虑你的两个组件HelOS并添加与这个方法的项目交互。@ Gurangddorda将与FixBasy一起工作吗?是的,首先你需要从FielBasic获取所有数据,然后将数据传递给组件属性,并且该数据再次被用作子组件的输入数据,<代码> < /代码>这是你的子组件。这样的数据..@output
然后您可以使用html格式的数据,如@input('childData')childPropData;
问题是,在执行代码后,没有任何内容显示在下拉列表中:(我现在不知道我做错了什么……你试过什么?你检查过stackblitz吗?是的,在实现代码后,组件中没有显示任何数据。{{childPropData.fieldName}