I need to implement a customized tooltip for ag-Grid in angular 6.
Following is my code :
app.component.ts
import { Component, OnInit } from '#angular/core';
import { MyTooltipComponent } from '../my-tooltip/my-tooltip.component';
#Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
})
export class AppComponent implements OnInit {
private frameworkComponents = {};
constructor() {
this.frameworkComponents = { myTooltipComponent: MyTooltipComponent };
}
aggridConfig0: any = {
rowData: [],
columnDefs: [],
defaultColDef: {
filter: true,
sortable: true,
resizable: false,
editable: false,
enableRowGroup: false,
tooltipComponent: "myTooltipComponent"
},
cubeXCreateAgGridColumn: (data) => {
let temp = [];
data.forEach((val, key) => {
if (key == 0) {
Object.keys(val).forEach((name) => {
temp.push({
headerName: name,
field: name,
tooltipField: tooltipName
})
})
}
});
return temp;
}
}
private gridApi0;
private gridColumnApi0;
agGrid;
onGridReady0(params) {
this.agGrid = [
{
"header1": "abc",
"header2": "efg"
},
{
"header1": "def",
"header2": "xyz"
}
];
this.gridApi0 = params.api;
this.gridColumnApi0 = params.columnApi;
this.aggridConfig0.rowData = this.agGrid;
this.gridApi0.setColumnDefs(this.aggridConfig0.cubeXCreateAgGridColumn(this.aggridConfig0.rowData));
}
}
app.component.html
<ag-grid-angular class="ag-theme-balham base-padding" style="height: 500px"
[rowData]="aggridConfig0.rowData"
[columnDefs]="aggridConfig0.columnDefs"
[defaultColDef]="aggridConfig0.defaultColDef"
[animateRows]="true"
[suppressDragLeaveHidesColumns]="true"
(gridReady)="onGridReady0($event)"
[frameworkComponents]="frameworkComponents">
</ag-grid-angular>
my-tooltip-component.ts
import {Component, ViewEncapsulation} from '#angular/core';
import {ITooltipAngularComp} from "#ag-grid-community/angular";
#Component({
selector: 'my-tooltip-component',
template: `
<div class="custom-tooltip">
<p><span>Header 1 : {{data.header1}}</span></p>
<p><span>Header 2 : {{data.header2}}</span></p>
</div>`,
styles: [
`
:host {
position: absolute;
width: 150px;
height: 70px;
border: 1px solid cornflowerblue;
overflow: hidden;
pointer-events: none;
transition: opacity 1s;
}
:host.ag-tooltip-hiding {
opacity: 0;
}
.custom-tooltip p {
margin: 5px;
white-space: nowrap;
}
.custom-tooltip p:first-of-type {
font-weight: bold;
}
`
]
})
export class MyTooltipComponent implements ITooltipAngularComp {
private params: any;
private data: any;
agInit(params): void {
this.params = params;
console.log("params here not printing............",params)
this.data = params.api.getDisplayedRowAtIndex(params.rowIndex).data;
this.data.color = this.params.color || 'white';
}
}
app.module.ts
import { BrowserModule } from '#angular/platform-browser';
import { NgModule } from '#angular/core';
import { BrowserAnimationsModule } from '#angular/platform-browser/animations';
import { AgGridModule } from 'ag-grid-angular';
import 'ag-grid-enterprise';
import { AppComponent } from './app.component';
import { AppRoutingModule } from './app-routing/app-routing.module';
import { MyTooltipComponent } from './component/my-tooltip/my-tooltip.component';
#NgModule({
declarations: [
AppComponent, MyTooltipComponent
],
imports: [
BrowserModule,
BrowserAnimationsModule,
AppRoutingModule,
AgGridModule.withComponents([MyTooltipComponent])
],
providers: [ ],
bootstrap: [AppComponent]
})
export class AppModule { }
Please find the stackblitz url here :
https://stackblitz.com/edit/my-tooltip-app
I am not able to show the customized data from my-tooltip.component.ts to the header1 column tooltip.
I have referred - https://www.ag-grid.com/javascript-grid-tooltip-component/
Please help me out. Thanks in advance
The issue is resolved now.
There was an issue with the AgGrdModule that I imported. Which was previously imported from ag-grid-angular library.
I changed it to #ag-grid-community/angular
In my app.module.ts
import { AgGridModule } from "#ag-grid-community/angular";
Thanks everyone..!!
Related
i'm trying some css test on my project, but one of my component don't want to show his css.
This is my Angular structure :
my app.component.html
<div id="nav-bar">
<div id="nav-bar-content">
<div id="nav-bar-left">
<div>Pangolin</div>
</div>
<div id="nav-bar-right">
<div>Register</div>
</div>
</div></div>
<router-outlet></router-outlet>
my app.component.css
#nav-bar {
border: solide 5px red;
}
my app.component.ts
import { Component } from '#angular/core';
#Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
title = 'socialnetworkapp';
}
and this is what i have in my browser :
and this is my app.module.ts
// built in
import { NgModule } from '#angular/core';
import { BrowserModule } from '#angular/platform-browser';
import { FormsModule } from '#angular/forms';
import { HttpClientModule } from '#angular/common/http';
import {MatButtonModule} from '#angular/material/button';
//component import
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { UserComponent } from './components/user/user.component';
import { LoginComponent } from './components/login/login.component';
import { AccountComponent } from './components/account/account.component';
import { PageOneComponent } from './components/page-one/page-one.component';
import { navbarComponent } from './components/navbar/navbar.component';
import { SignUpComponent } from './components/sign-up/sign-up.component';
import { BrowserAnimationsModule } from '#angular/platform-browser/animations';
#NgModule({
declarations: [
AppComponent,
UserComponent,
LoginComponent,
AccountComponent,
PageOneComponent,
navbarComponent,
SignUpComponent
],
imports: [
BrowserModule,
AppRoutingModule,
FormsModule,
HttpClientModule,
MatButtonModule,
BrowserAnimationsModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
My /src/app/components/page-one module works perfectly. Is it some children, parents issue there ? I'm new on Angular
Your CSS is incorrect, solide should be solid:
#nav-bar {
border: solid 5px red;
}
See MDN border-style for a full list of valid border styles.
I'm using this tutorial to display simple dialog.
The problem is that the dialog displays empty and the console show no error.
Even when i try to change parts from my dialog.component.html, or from dress-form.ts, nothing changes.
Here is my component from where i open the dialog (dress-form.ts):
import { MatDialog } from '#angular/material/dialog';
import { DialogComponent } from 'src/app/dialog/dialog.component';
#Component({
selector: 'dress-form',
styleUrls: ['dress-form.css'],
templateUrl: 'dress-form.component.html',
})
export class DressFormComponent {
constructor(public dialog: MatDialog) { }
openDeleteDialog() {
const dialogRef = this.dialog.open(DialogComponent, {
});
dialogRef.afterClosed().subscribe(result => {
console.log('The dialog was closed');
})
}
}
that is my dialog component (dialog.component.ts):
import { Component, OnInit, Inject } from '#angular/core';
import { MatDialogRef } from '#angular/material/dialog';
import { MAT_DIALOG_DATA } from '#angular/material/dialog';
#Component({
selector: 'dialog',
styleUrls: ['dialog.css'],
templateUrl: 'dialog.component.html',
})
export class DialogComponent implements OnInit {
constructor(public dialogRef: MatDialogRef<DialogComponent>,
#Inject(MAT_DIALOG_DATA) public data: any) { }
ngOnInit() {
}
okToDelete() {
this.dialogRef.close();
console.log("this item will be deleted!")
}
}
dialog.component.html:
<html lang="he" dir="rtl"></html>
<h2 mat-dialogititle>tile</h2>
<mat-dialog-content>
<p>this is the content</p>
</mat-dialog-content>
<mat-dialog-actions>
<button mat-button mat-dialog-close>cancel</button>
<button mat-button (click)="okToDelete()">delete</button>
</mat-dialog-actions>
app.module.ts:
import { BrowserModule } from '#angular/platform-browser';
import { NgModule } from '#angular/core';
import { AppRoutingModule, RoutingComponent } from './app-routing.module';
import { AppComponent } from './app.component';
import { DressesComponent } from './dresses/dresses.component';
import { HttpClientModule } from '#angular/common/http';
import { DressesService } from './services/dresses.service';
import { BrowserAnimationsModule } from '#angular/platform-browser/animations';
import { MatTableModule } from '#angular/material/table';
import { MatSelectModule } from '#angular/material/select';
import { MatDialogModule } from '#angular/material/dialog';
import { MatInputModule } from '#angular/material/input';
import { LoadingSpinnerComponent } from './ui/loading-spinner/loading-spinner.component';
import { MatToolbarModule } from '#angular/material/toolbar';
import { MatIconModule } from '#angular/material/icon';
import { ButtonToggle } from './button-toggle/button-toggle.component';
import { MatButtonToggleModule } from '#angular/material/button-toggle';
import { Sidenav } from './side-nav/side-nav.component';
import { MatSidenavModule } from '#angular/material/sidenav';
import { StockService } from './services/stock.service';
import { MatPaginatorModule } from '#angular/material/paginator';
import { MatSortModule } from '#angular/material/sort'
import { FormsModule, ReactiveFormsModule } from '#angular/forms';
import { MatCardModule } from '#angular/material/card';
import { TestComponent } from './test/test.component'
import { MatDividerModule } from '#angular/material/divider';
import { MatButtonModule } from '#angular/material/button';
import { UpdateStockTableComponent } from './dresses/dress-form/update-stock-table/update-stock-table.component'
import { SearchTableService } from './services/search-table.service';
import { MatSlideToggleModule } from '#angular/material/slide-toggle'
import { MatTabsModule } from '#angular/material/tabs';
import { DressDetailsComponent } from './stock/stock-form/dress-detils/dress-details.component';
import { FixesComponent } from './stock/stock-form/fixes/fixes.component';
import { DialogComponent } from './dialog/dialog.component';
#NgModule({
declarations: [
AppComponent,
DressesComponent,
LoadingSpinnerComponent,
ButtonToggle,
Sidenav,
RoutingComponent,
TestComponent,
UpdateStockTableComponent,
DressDetailsComponent,
FixesComponent,
DialogComponent
],
imports: [
BrowserModule,
AppRoutingModule,
HttpClientModule,
BrowserAnimationsModule,
MatTableModule,
MatSelectModule,
MatDialogModule,
MatInputModule,
MatToolbarModule,
MatIconModule,
MatButtonToggleModule,
MatSidenavModule,
MatPaginatorModule,
MatSortModule,
BrowserAnimationsModule,
FormsModule,
ReactiveFormsModule,
MatCardModule,
MatDividerModule,
MatButtonModule,
MatSlideToggleModule,
MatTabsModule
],
entryComponents: [DialogComponent],
providers: [DressesService, StockService, SearchTableService],
bootstrap: [AppComponent]
})
export class AppModule { }
Had the exact same issue and couldn't find a solution anywhere. Like you I had my selector name as 'dialog', after changing this to 'app-dialog' it worked as expected.
According do your code the problem should be in the html of dialog component
<html lang="he" dir="rtl"></html> // remove this line no nee for this one
// <h2 mat-dialogititle>tile</h2>
// Change the abouve line to this line
<h2 mat-dialog-title>Install Angular</h2>
<mat-dialog-content>
<p>this is the content</p>
</mat-dialog-content>
<mat-dialog-actions>
<button mat-button mat-dialog-close>cancel</button>
<button mat-button (click)="okToDelete()">delete</button>
</mat-dialog-actions>
Read more about rtl support in angular in docs https://material.angular.io/cdk/bidi/overview
I am working on angular formio, in that I am using a custom css class, name CustomCSS I have added the same in css file as follows
Here is stackblitz
app.component.scss
.CustomCSS {
margin: auto;
width: 50%;
border: 3px solid rgb(1, 248, 1);
padding: 10px;
background-color: coral;
}
app.component.ts
#Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
})
export class AppComponent implements OnInit {
ngOnInit() {
debugger;
this.triggerRefresh = new EventEmitter();
this.http.get('http://....')
.subscribe(
response => {
this.form = response.json();// this is my html script from DB
},
err => {console.error(err)}
);
}
}
app.component.html
<formio [refresh]="triggerRefresh" [form]="form" [submission]="submission" (submit)="onSubmit($event)"></formio>
My Html this.form script as follows
{
"components":[
{
"label":"City",
"widget":"choicesjs",
"customClass":"CustomCSS",
"tableView":true,
"data":{
"values":[
{
"label":"abc",
"value":"abc"
]
},
"selectThreshold":0.3,
"calculateServer":false,
"validate":{
"required":true
},
"key":"city",
"type":"select",
"indexeddb":{
"filter":{
}
},
"input":true
},
{
"type":"button",
"label":"Submit",
"key":"submit",
"disableOnInvalid":true,
"input":true,
"tableView":false
}
],
"id":4
}
In my script also the css class name available but it is not appending in the view.
One possible way to make it work from your component is to modify the style encapsulation for that component.
import { Component, OnInit, ViewEncapsulation } from '#angular/core'; // <-- add ViewEncapsulation
#Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: [ './app.component.css' ],
encapsulation: ViewEncapsulation.None // <-- add this line
})
More information on encapsulation.
That being said.
I still recommend to use global styles and implement css selectors to target formio generated html elements like in your example:
#app formio .control-label {
font-weight: bold;
}
This is my app.routing.module.ts code :
import { NgModule } from '#angular/core';
import { Routes, RouterModule } from '#angular/router';
import { PageLoginComponent } from './components/page-login/page-login.component';
import { LoginGuard } from './login.guard';
import { DashboardComponent } from './components/dashboard/dashboard.component';
import { CreatedDatasourcesComponent } from './components/created-datasources/created-datasources.component';
import { RegisterComponent } from './components/register/register.component';
const routes: Routes = [
{ path: '', component: PageLoginComponent },
{ path: 'login', component: PageLoginComponent },
{
path: 'signup',
component: RegisterComponent
},
{
path: 'dashboard',
canActivate: [LoginGuard],
children: [
{ path: '', component: DashboardComponent }
]
},
{ path: 'datasources', component: CreatedDatasourcesComponent },
{ path: 'datasources/:status', component: CreatedDatasourcesComponent },
];
#NgModule({
imports: [RouterModule.forRoot(routes, {useHash: true})],
exports: [RouterModule]
})
export class AppRoutingModule { }
This is app.module.ts code :
import { BrowserModule } from '#angular/platform-browser';
import { NgModule } from '#angular/core';
import { HttpModule } from '#angular/http';
import { HttpClientModule, HTTP_INTERCEPTORS } from '#angular/common/http';
import { FormsModule } from '#angular/forms';
import { BrowserAnimationsModule } from '#angular/platform-browser/animations';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { PageLoginComponent } from './components/page-login/page-login.component';
import { LoginService } from './services/login.service';
import { LoginGuard } from './login.guard';
import { CustomInterceptor } from './custom-interceptor.service';
import { GetsrcdestService } from './services/getsrcdest.service';
import { DashboardComponent } from './components/dashboard/dashboard.component';
import { DatasourcesComponent } from './components/datasources/datasources.component';
//import { MatFormFieldModule } from '#angular/material/form-field';
import { ConnectionsContainerComponent } from './components/connections/connections-container/connections-container.component';
import { ConnectionsSelectorComponent } from './components/connections/connections-selector/connections-selector.component';
import { ConnectionsSearchComponent } from './components/connections/connections-search/connections-search.component';
import { ConnectionsListComponent } from './components/connections/connections-list/connections-list.component';
import { BackdropComponent } from './components/backdrop/backdrop.component';
import { ConnectionsSourceValidatorComponent } from './components/connections/connections-source-validator/connections-source-validator.component';
import { ConnectionsDestinationValidatorComponent } from './components/connections/connections-destination-validator/connections-destination-validator.component';
import { IsvalidService } from './services/isvalid.service';
import { ConnectionsDestinationFormComponent } from './components/connections/connections-destination-form/connections-destination-form.component';
import { ConnectionsFilterEndpointsComponent } from './components/connections/connections-filter-endpoints/connections-filter-endpoints.component';
import { FetchdbsService } from './services/fetchdbs.service';
import { ValidateService } from './services/validate.service';
import { ConnectionsSchedulerComponent } from './components/connections/connections-scheduler/connections-scheduler.component';
import { NavbarComponent } from './components/navbar/navbar.component';
import { ConnectionsStepperComponent } from './components/connections/connections-stepper/connections-stepper.component';
import { NgbModule, NgbDropdown } from '#ng-bootstrap/ng-bootstrap';
import { MatSidenavModule } from '#angular/material/sidenav';
import { CreatedDatasourcesComponent } from './components/created-datasources/created-datasources.component';
import { MatExpansionModule } from '#angular/material/expansion';
import { MatTableModule } from '#angular/material';
import { ChartsModule } from 'ng2-charts';
import { SidenavComponent } from './components/sidenav/sidenav.component';
import { DashboardDataService } from './dashboard-data.service';
import { LandingPageComponent } from './components/landing-page/landing-page.component';
import{FooterComponent} from './components/footer/footer.component';
import{RegisterComponent} from './components/register/register.component';
import { AlertService } from './services/alert.service';
import { SignupService } from './services/signup.service';
import{ReactiveFormsModule} from '#angular/forms'
#NgModule({
declarations: [
AppComponent,
PageLoginComponent,
DashboardComponent,
DatasourcesComponent,
ConnectionsContainerComponent,
ConnectionsSelectorComponent,
ConnectionsSearchComponent,
ConnectionsListComponent,
BackdropComponent,
ConnectionsSourceValidatorComponent,
ConnectionsDestinationValidatorComponent,
ConnectionsDestinationFormComponent,
ConnectionsFilterEndpointsComponent,
ConnectionsSchedulerComponent,
NavbarComponent,
ConnectionsStepperComponent,
CreatedDatasourcesComponent,
SidenavComponent,
LandingPageComponent,
FooterComponent,
RegisterComponent
],
imports: [
BrowserModule,
BrowserAnimationsModule,
AppRoutingModule,
FormsModule,
HttpModule,
HttpClientModule,
NgbModule.forRoot(),
MatSidenavModule,
MatExpansionModule,
MatTableModule,
ChartsModule,
ReactiveFormsModule
],
providers: [
LoginService,
GetsrcdestService,
IsvalidService,
FetchdbsService,
ValidateService,
DashboardDataService,
AlertService,
SignupService,
{ provide: HTTP_INTERCEPTORS, useClass: CustomInterceptor, multi: true },
LoginGuard
],
bootstrap: [LandingPageComponent]
})
export class AppModule { }
and following is the line of code where i am calling the component
<li class="nav-item active">
<a routerLink="signup" class="nav-link">SignUp</a>
</li>
Have imported new component everywhere, in app.module.ts as well in routing file still it is not working, not showing any console error.
While clicking on the link it is showing in url /signup but component is not showing up.
How to solve this issue and how to give link of following code to work?
I need to make a traffic light that from 0 to 10 minutes is green from 10 to 20 yellow and from 20 to 30 red, time is by service
So far this is my code
This is the component
import {
Component,
OnInit,
Input
} from '#angular/core';
import {
TiempoService
} from "app/servicios/tiempo.service"
#Component({
selector: 'app-menu',
templateUrl: './menu.component.html',
styleUrls: ['./menu.component.css']
})
export class MenuComponent implements OnInit {
#Input() tiemposervice: TiempoService;
constructor() {}
ngOnInit() {
}
}
This is the HTML
<div class="row">
<div class="small-12 medium-6 columns">
<span>Tiempo transcurrido</span>
<h5>{{tiempoTranscurrido | date:'mm:ss'}}</h5>
</div>
</div>
This is the service
import {
Injectable
} from '#angular/core';
import Rx from 'Rx';
#Injectable()
export class TiempoService {
tiempoTranscurrido: number;
constructor() {}
ngOnInit() {
}
tiempoTotal() {
Rx.Observable.interval(1000).subscribe(segundos => {
this.tiempoTranscurrido = segundos * 1000;
})
}
}
I would greatly appreciate your help.
I suggest you need something like this:
Service:
import { Injectable } from '#angular/core';
import { Observable } from 'rxjs';
#Injectable()
export class LightService {
getLight(interval): Observable<string> {
return Observable.interval(interval)
.timeInterval()
.map(time => {
if(time.value % 3 === 2) {
return 'green';
} else if(time.value % 3 === 0) {
return 'yellow';
} else if (time.value % 3 === 1) {
return 'red';
}
});
}
}
Component:
import { Component, OnInit } from '#angular/core';
import { LightService } from './light.service';
#Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css'],
providers: [ LightService ]
})
export class AppComponent implements OnInit {
light: string = "green";
constructor(private lightService: LightService) {}
ngOnInit() {
this.lightService
.getLight(10000) // 10 seconds interval
.subscribe(light => this.light = light);
}
}
Template:
<h1>
{{ light }}
</h1>
<ul>
<li *ngIf="light === 'green'" class="green"></li>
<li *ngIf="light === 'yellow'" class="yellow"></li>
<li *ngIf="light === 'red'" class="red"></li>
</ul>
Styles:
ul {
list-style-type: none;
margin: 0;
padding: 0;
}
li {
width: 64px;
height: 64px;
border-radius: 50%;
border: 1px solid black;
}
.green {
background-color: green;
}
.yellow {
background-color: yellow;
}
.red {
background-color: red;
}
If you need to show lights only once add take operator:
import { Injectable } from '#angular/core';
import { Observable } from 'rxjs';
#Injectable()
export class LightService {
getLight(interval): Observable<string> {
return Observable.interval(interval)
.timeInterval()
.map(time => {
if(time.value % 3 === 2) {
return 'green';
} else if(time.value % 3 === 0) {
return 'yellow';
} else if (time.value % 3 === 1) {
return 'red';
}
})
.take(2);
}
}