Following the instructions of https://www.primefaces.org/primeng/#/dropdown i'm trying to do one, but list options are not displayed.
Edit: It's fixed. I inderstood it wrong. I thought that i could get languages from an external class in order to reuse the component. Probably it's possible, but that's something i still don't know how to do. If someone could help me with that, i would really appreciate that.
Those are my classes:
Idioma.ts
export interface Idiomas {
name: string;
code: string;
}
export class Idioma{
languages: Idiomas[];
selectedLanguage:Idiomas;//Selected language unused
constructor(){
this.languages=[
{name: 'Español', code: 'SPA'},
{name: 'Deutsch', code: 'GER'},
{name: 'български език', code: 'BUL'},
{name: 'Hrvatski', code: 'CRO'},
{name: 'Dansk', code: 'DEN'},
{name: 'Dlovenčina', code: 'SLK'},
{name: 'Slovenščina', code: 'SLN'},
{name: 'Eesti keel', code: 'STN'},
{name: 'Suomi', code: 'FIN'},
{name: 'Français', code: 'FRA'},
{name: 'Ελληνική γλώσσα', code: 'GRE'},
{name: 'Nedarlands', code: 'HOL'},
{name: 'Magyar', code: 'HUN'},
{name: 'English', code: 'ENG'},
{name: 'Italiano', code: 'ITA'},
{name: 'Latviešu valoda', code: 'LET'},
{name: 'Lietuvių kalba', code: 'LIT'},
{name: 'Polski', code: 'POL'},
{name: 'Portugués', code: 'POR'},
{name: 'Čeština', code: 'CHE'},
{name: 'Limba română', code: 'RUM'},
{name: 'Svenska', code: 'SWE'}
]
}
}
header.component.ts
import { Component, OnInit } from '#angular/core';
import {Idioma, Idiomas} from "../../classes/Idioma";//Idioma unused
#Component({
selector: 'app-header',
templateUrl: './header.component.html',
styleUrls: ['./header.component.scss']
})
export class HeaderComponent implements OnInit {
languages:Idioma[];
selectedLanguage: Idioma;
constructor() {
}
ngOnInit() {
}
}
header.component.html
<p-dropdown [options]="languages" [(ngModel)]="selectedLanguage" optionLabel="name" placeholder="Idiomas"></p-dropdown>
And that's what i get:
When i click on the dropdown
What am i doing wrong?
To solve it a changed as follows:
app.module.ts
import {FormsModule} from "#angular/forms";
Idiomas.ts
export interface Idiomas {
label: string;
code: string;
}
header.component.ts
import { Component, OnInit } from '#angular/core';
import {Idiomas} from "../../classes/Idiomas";
#Component({
selector: 'app-header',
templateUrl: './header.component.html',
styleUrls: ['./header.component.scss']
})
export class HeaderComponent implements OnInit {
languages: Idiomas[];
selectedLanguage:Idiomas;
constructor(){
this.languages=[
{label: 'Español', code: 'SPA'},
{label: 'Deutsch', code: 'GER'},
{label: 'български език', code: 'BUL'},
{label: 'Hrvatski', code: 'CRO'},
{label: 'Dansk', code: 'DEN'},
{label: 'Dlovenčina', code: 'SLK'},
{label: 'Slovenščina', code: 'SLN'},
{label: 'Eesti keel', code: 'STN'},
{label: 'Suomi', code: 'FIN'},
{label: 'Français', code: 'FRA'},
{label: 'Ελληνική γλώσσα', code: 'GRE'},
{label: 'Nedarlands', code: 'HOL'},
{label: 'Magyar', code: 'HUN'},
{label: 'English', code: 'ENG'},
{label: 'Italiano', code: 'ITA'},
{label: 'Latviešu valoda', code: 'LET'},
{label: 'Lietuvių kalba', code: 'LIT'},
{label: 'Polski', code: 'POL'},
{label: 'Portugués', code: 'POR'},
{label: 'Čeština', code: 'CHE'},
{label: 'Limba română', code: 'RUM'},
{label: 'Svenska', code: 'SWE'}
]
}
ngOnInit() {
}
}
It should work with optionLabel="name". I am using it this way.
You don't have any error in console ?
Maybe in your real code you are getting your options asynchronuously and you have to wait for it to be ready ?
<p-dropdown *ngIf="!!languages" [options]="languages" [(ngModel)]="selectedLanguage" optionLabel="name" placeholder="Idiomas"></p-dropdown>
Related
I'm using nest and swagger and I have a question.
I wrote the code as below. But in swagger nothing render in request body.
Is it a picktype problem?
Please tell me how to solve it.
thank you
#ApiOperation({ summary: 'about payment' })
#ApiBody({ type: PaymentDto })
#ApiResponse({
type: PaymentResponseDto,
})
#Patch('payment')
async payment(
#Body() paymentDto: PaymentDto,
)
export class PaymentDto extends PickType(Renewal, [
'renewalMethod',
'renewalPrice',
]) {}
#Entity()
export class Renewal{
#ApiProperty({
example: '9,900',
description: 'price',
})
#IsNumber()
#Column({ default: 0 })
renewalPrice: number;
#ApiProperty({
example: 'subs',
description: 'type',
})
#IsEnum(RenewalType)
#Column({ type: 'enum', enum: RenewalType })
renewalMethod: RenewalType;
}
result browser Image
Hello i want to insert a select dropdownlist with angular material.
My question is where we put this exactly :
export interface Food {
value: string;
viewValue: string;
}
export class SelectOverviewExample {
foods: Food[] = [
{value: 'steak-0', viewValue: 'Steak'},
{value: 'pizza-1', viewValue: 'Pizza'},
{value: 'tacos-2', viewValue: 'Tacos'}
];
}
Link of the component
I did this :
app.module .ts
import { BrowserModule } from '#angular/platform-browser';
import { NgModule } from '#angular/core';
import {MatTabsModule} from '#angular/material/tabs';
import {MatSelectModule} from '#angular/material/select';
import {MatInputModule} from '#angular/material/input';
import { AppComponent } from './app.component';
import { BrowserAnimationsModule } from '#angular/platform-browser/animations';
import { InterfaceComponent } from './interface/interface.component';
#NgModule({
declarations: [
AppComponent,
InterfaceComponent
],
imports: [
BrowserModule,
MatTabsModule,
BrowserAnimationsModule,
MatSelectModule,
MatInputModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
And i added html code in app.component.html
Result :
select list but without options cause i didn't know where i will put the export details
enter image description here
for this case you have to put in the app.component.ts like:
import { Component } from '#angular/core';
interface Food {
value: string;
viewValue: string;
}
#Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
})
export class AppComponent {
foods: Food[] = [
{value: 'steak-0', viewValue: 'Steak'},
{value: 'pizza-1', viewValue: 'Pizza'},
{value: 'tacos-2', viewValue: 'Tacos'}
];
}
I am trying to plot wind barb using my angular application. I used angular-highchart package but it's showing me below error -
Error: Highcharts error #17: www.highcharts.com/errors/17
import { Component } from '#angular/core';
import { Chart } from 'angular-highcharts';
import { MapChart } from 'angular-highcharts';
#Component({
selector: 'app-root',
template: `
<div [chart]="chart"></div>
`
})
export class AppComponent {
chart = new Chart({
title : { text : 'simple chart' },
xAxis: {
type: 'datetime',
offset: 40
},
series: [{
type: 'windbarb',
name:"Wind Direction",
data: [
[9.8, 177.9],
[10.1, 177.2]
]
}, {
type: 'area',
name:'WindSpeed',
data: [
[9.8, 177.9],
[10.1, 177.2]
],
}]
});
constructor() {
}
}
here
Check module.ts imports as per angular-highcharts docs
import { NgModule } from '#angular/core';
import { BrowserModule } from '#angular/platform-browser';
import { FormsModule } from '#angular/forms';
import { ChartModule, HIGHCHARTS_MODULES } from 'angular-highcharts';
import exporting from 'highcharts/modules/exporting.src';
import windbarb from 'highcharts/modules/windbarb.src';
export function highchartsModules() {
// apply Highcharts Modules to this array
return [ exporting,windbarb ];
}
import { AppComponent } from './app.component';
import { HelloComponent } from './hello.component';
#NgModule({
imports: [ BrowserModule, FormsModule,ChartModule ],
declarations: [ AppComponent, HelloComponent ],
providers: [
{ provide: HIGHCHARTS_MODULES, useFactory: highchartsModules } // add as factory to your providers
],
bootstrap: [ AppComponent ]
})
export class AppModule { }
Stackblitz demo
I'm using angular 2, firebase and ng2-highcharts.
I assign data after I receive them from firebase like so :
this.items = af.database.list('/items');
this.optionsAsync = this.items.map(data => {
this.options.series[0].data = data.map(item => ([item.x, item.y]));
return this.options;
});
Then in my view template I have :
<div [ng2-highcharts]="optionsAsync | async"></div>
This is working fine at first load. But unfortunately when new data are received chart is not updated. Any idea ?
I found a solution by referencing highcharts component with #ViewChild like so :
in component class :
import { ViewChild, Component } from '#angular/core';
#Component({
selector: 'app-root',
templateUrl: 'app.component.html',
styleUrls: ['app.component.css'],
directives: [Ng2Highcharts]
})
export class AppComponent {
#ViewChild(Ng2Highcharts)
chartElement: Ng2Highcharts;
private chartData = {
chart: {
zoomType: 'x'
},
colors: ['rgba(255,0,255,1)'],
title: {
text: 'Items'
},
credits: '',
series: [{
type: 'area',
name: 'Items',
data: []
}]
};
chartData$ = new Subject();
ngOnInit() {
this.items.subscribe((data: any) => {
this.chartData.series[0].data = data.map(item => ([item.x, parseFloat(item.y)]) );
this.chartData$.next(this.chartData);
if(this.chartElement && this.chartElement.chart) {
var serieRef = this.chartElement.chart.series[0];
serieRef.setData(this.chartData.series[0].data);
}
});
}
}
I'm building a REST api with grails 3 and mongo. I have encountered a problem when i need to marshal an object graph with a bigger depth.
I have the following domains:
class Category extends Resource {
/* other fields */
Category parent
}
class Product extends Resource {
/* other fields */
List<Category> categories
static hasMany = [categories: Category]
}
I have in the database the following structure(simplified for the sake of understanding):
categories:
{name: 'cat1'}
{name: 'cat2', parent: 'cat3'}
{name: 'cat3', parent: 'cat4'}
{name: 'cat4', parent: 'cat5'}
{name: 'cat5'}
product:
{categories: ['cat1', 'cat2']}
I am extending from RestfullController when creating my controllers. I want to be able to get a product and have the categories with parents in the returned json.
I get the following results:
/product/${id}
{
id: '...',
categories: [{
id: '...',
name: 'cat1'
}, {
id: '...',
name: 'cat2',
parent: { id: '...' }
}]
}
/category/cat2id
{
id: '...',
name: 'cat2',
parent: { id: '...' }
}
/category
[{
id: '...',
name: 'cat1'
},{
id: '...',
name: 'cat5'
},{
id: '...',
name: 'cat4',
parent: {
id: '...',
name: 'cat5'
}
},{
id: '...',
name: 'cat3',
parent: {
id: '...',
name: 'cat4',
parent: {
id: '...',
name: 'cat5'
}
}
},{
id: '...',
name: 'cat2',
parent: {
id: '...',
name: 'cat3',
parent: {
id: '...',
name: 'cat4',
parent: {
id: '...',
name: 'cat5'
}
}
}
}]
Why would Category.list() load the whole category object graph, and Category.get(), Product.get() and Product.list() would not load it? Is there a way to control this behaviour ?
The way Grails works is that it will only render associations that have already been loaded from the database, hence why you get some associations rendered and others not.
There is no built in way to control this behaviour other than writing your own marshaller. See http://grails.github.io/grails-doc/latest/guide/webServices.html#renderers