Show/Hide Divs dynamically in angular - html

I have 5 divs on my page. When my form is loaded, all 5 divs gets populated with some data. However, I have to display only 3 div at a time and when user takes any action or clicks on cross(X) sign on
any div, we have to display next div.
Need to figure out how to display only 3 records i.e. only 3 div ?
At a time max 3 divs can be displayed
//Model
export class Bird{
id: number;
name: string;
}
This is the sample collection that we need to display in DIV on form
arrBirds: Birds [] = [
{ id:1, name: 'Bells Sparrow' },
{ id:2, name: 'Mourning Dove'},
{ id:3, name: 'Bald Eagle' },
{ id:4, name: 'Sparrow' }
{ id:5, name: 'Parrot' }
];
//html
This is how, I am displaying the data in DIV on form.
<div *ngFor='let bird of arrBirds' (click)="onSelection(bird)">
<div>{{ bird.name }}</div>
</div>
// this code is to take any action on what user has selected in div
<div *ngIf="selectedBird">
{{selectedBird.id}} {{selectedBird.name}}
</div>
//
onSelection(userSelectedBird: Bird}{
this.selectedBird = userSelectedBird;
}

You should define array of pages with 'active' state, i.e
const pages = [{
id: 1,
name: 'page1'
active: true
}, {
id: 2,
name: 'page2'
active: true
}, {
id: 3,
name: 'page3'
active: true
}, {
id: 4,
name: 'page4'
active: false
}, {
id: 5,
name: 'page5'
active: false
}]
Based on selection, you can set active flag true/false. You can use active Property with *ngIf in the Template file.
https://stackblitz.com/edit/angular-sxzrlp

Related

How to remove specific lines with a pattern inside a json file?

I have a very large json file with an error that I need to fix.
{
id: 1,
name: 'Human',
type: {
id: { <==== here
id: 2,
name: 'Body',
image: 'body.png',
}, <==== here
},
},
I need to remove this id: { and the closing brace } lines inside type. How to remove them to make the object look like this?
{
id: 1,
name: 'Human',
type: {
id: 1,
name: 'Body',
image: 'body.png',
},
},

vuetify vue.js pug - Show title only when more then one option group is displayed

The heading should only be displayed in a vuetify component if more than one option group is displayed.
If only one option group is displayed, the heading should not be displayed.
I need a code like:
if (e-switch-option more than one) --> display, else display none
let name = 'm-list-options';
export default {
name: name,
mixins: [switchList],
props: {
name: {
type: String,
default: name
},
dividers: {
type: Boolean,
default: false
},
section: {
type: Object,
required: true
},
disabled: {
type: Boolean,
default: false
}
},
computed: {
optionClass() {
return [
'ma-0',
{
'e-switch-option__disable-events': this.disabled
}
]
},
}
}
<template lang="pug">
v-layout(wrap)
v-flex(xs12)
m-list(:items="section.children" v-on="$listeners" :dividers="dividers")
template(#title="") {{section.title}}
template(#template="{item, index}")
e-switch-option(:value="index"
:key="`option-${item.id}`"
:class="optionClass"
v-bind="$attrs"
v-on="$listeners") {{item.title}}
</template>

Possible to share logic among Components?

I have several components that all do the same thing:
display a form (the form varies though, so the HTML differs for each)
capture the form
validate and send the form using a REST API
There are certain things I'm looking to share among the components. For example, the forms all have a list of RadioButtons with the following values:
#Input() radioList: Object[] = [
{ label: 'Unsatisfactory', value: 1 },
{ label: 'Needs Improvement', value: 2 },
{ label: 'Meets Expectations', value: 3 },
{ label: 'Exceeds Expectations', value: 4 },
{ label: 'Outstanding', value: 5 }
];
Is there any way to share stuff like this so if I want to edit that RadioList, I don't have to do it four times?
Extend class?
//property and property-level annotations (#Input) will be picked up by ancestors
export abstract class RadioListAwareComponent{
#Input() radioList: Object[] = [
{ label: 'Unsatisfactory', value: 1 },
{ label: 'Needs Improvement', value: 2 },
{ label: 'Meets Expectations', value: 3 },
{ label: 'Exceeds Expectations', value: 4 },
{ label: 'Outstanding', value: 5 }
];
}
#Component({
template: `<div>Comp1</div>`
})
export class RadioListImplComponentONE extends RadioListAwareComponent{}
#Component({
template: `<div>Comp2</div>`
})
export class RadioListImplComponentTWO extends RadioListAwareComponent{}
You can make your own factory and inject it into your controller https://docs.angularjs.org/guide/providers

Angular4 error message shows code which differs from the code that's supposed to be serving

I'm writing an app to go into a website, which is intended to calculate simplex algorithms. At the moment I am attempting to create functionality whereby the user can enter the number of coefficients and constraints, name these whatever they wish, and have the app spawn the relevant number and type of UI elements relative to the user's input. Here's what appears to be the relevant portion of the code (app.component.ts):
import { Component } from '#angular/core';
[...]
export class UIComponent {
id: 1;
name: string;
value: number;
type: string;
}
//* Mock data */
const UICOMPONENTS: UIComponent[] = [
{ id: 1, name: 'coefficient1', value: 4, type: '1dslide' },
{ id: 2, name: 'constraint1', value: 2, type: '2dslide' },
{ id: 3, name: 'min_max', value: 0, type: 'switch' },
{ id: 4, name: 'profit', value: 100, type: 'num_output' }
];
[...]
export class AppComponent {
title = 'SimutronX';
uicomponents = UICOMPONENTS;
[...]
}
This produces an error on screen saying:
Failed to compile.
/root/simutronx/simutron-app/src/app/app.component.ts (18,49): ',' expected.
Which relates to this line:
{ id: 2, name: 'constraint1', value: 2, type: '2dslide' },
Specifically the digit 2 in 2dslide. The error message (it's extremely long so I won't reproduce it all) also includes:
./src/app/app.component.ts
Module parse failed: /root/simutronx/simutron-app/node_modules/#ngtools/webpack/src/index.js!/root/simutronx/simutron-app/src/app/app.component.ts Unexpected token (22:85)
You may need an appropriate loader to handle this file type.
| var UICOMPONENTS = [
| { id: 1, name: 'coefficient1', value: 4, type: '1dslide' },
| { id: 2, name: 'constraint1, value: 2, type: ', 2: dslide, ' },: { id: 3, name: 'min_max', value: 0, type: 'switch' }, },
| { id: 4, name: 'profit', value: 100, type: 'num_output' }
| ];
Which is particularly confusing since, as you can see, that's not how I wrote the code. What's going on here?
You have an error in UIComponent type :
export class UIComponent {
id: number; //HERE
name: string;
value: number;
type: string;
}
Here a plunker :http://plnkr.co/edit/e6GrylSWznwbYD9VpK2C

Kendo Grid pager buttons

there is an option in the grid pageable.previousNext
If set to true the pager will display buttons for going to the first, previous, next and last pages. By default those buttons are displayed.
My question is: Is there a way to display only next and last buttons? If i set it false it hides all the buttons, and true display them.
Reading the source code it doesn't look like there is an option in kendo, don't know if you guy know a work around?
<div id="grid"></div>
<script>
$("#grid").kendoGrid({
columns: [
{ field: "productName" },
{ field: "category" }
],
dataSource: [
{ productName: "Tea", category: "Beverages" },
{ productName: "Coffee", category: "Beverages" },
{ productName: "Ham", category: "Food" },
{ productName: "Bread", category: "Food" }
],
pageable: {
pageSize: 2,
previousNext: false
}
});
</script>
Thanks,
Henry
The pager link contains following classes.
k-pager-first - class on first page link
k-pager-last - class on last page link
classes on all other page links
k-pager-numbers
- data-page="2"
- data-page="3"
etc
You can user jQuery, and disable links you don't want user to use.
not very elegant but should work.