Hello Everyone! In today's video we'll look at how to build an Angular 2 dashboard in under five minutes. If you haven't watched our Getting Started videos, I highly encourage you to do so as this will walk you through project setup.
  1. Using multiple Wijmo Controls inside an Angular 2 Component

  2. Create a shared data source

  3. Bind Wijmo controls to shared data source


Getting Started Videos (5-7 minutes each)

  1. FlexGrid QuickStart

  2. FlexChart QuickStart

  3. Input QuickStart


Video




Code Snips


Our DataSvc
import { Injectable } from 'angular2/core';

@Injectable()
export class DataSvc {
getData(countries: string[]): any[] {
var data = [];
for (let i = 0; i < countries.length; i++) {
data.push({
country: countries[i],
downloads: Math.round(Math.random() * 20000),
sales: Math.random() * 10000,
expenses: Math.random() * 5000
});
}
return data;
}
}

app.ts
// required for beta
///<reference path="../node_modules/angular2/typings/browser.d.ts"/>

/** Requred Angular 2 Libraries **/
import {Component, View, EventEmitter, provide, Input, Inject, enableProdMode} from 'angular2/core';
import { CORE_DIRECTIVES } from 'angular2/common';
import { bootstrap } from 'angular2/platform/browser';

// Wijmo Input, FlexChart, and FlexGrid Modules
import * as wjInput from 'wijmo/wijmo.angular2.input';
import * as wjNg2FlexGrid from 'wijmo/wijmo.angular2.grid';
import * as wjNg2FlexChart from 'wijmo/wijmo.angular2.chart';

// Shared DataService
import { DataSvc } from './DataSvc';

@Component({
selector: 'app',
templateUrl: '/src/app.html',
directives: [wjInput.WjInputDate, wjInput.WjComboBox,
wjNg2FlexChart.WjFlexChart, wjNg2FlexChart.WjFlexChartAxis,
wjNg2FlexChart.WjFlexChartLegend, wjNg2FlexChart.WjFlexChartDataLabel, wjNg2FlexChart.WjFlexChartSeries,
wjNg2FlexGrid.WjFlexGrid, wjNg2FlexGrid.WjFlexGridColumn, CORE_DIRECTIVES] // Directives needed imported from common
})
export class AppCmp {
countries = 'US,Germany, UK, Japan, Greece'.split(',');
// Initialize data as a Wijmo Collectionview
data: wijmo.collections.CollectionView;
protected dataSvc: DataSvc;
constructor( @Inject(DataSvc) dataSvc: DataSvc) {
this.dataSvc = dataSvc;
// Bound data to a collectionView
this.data = new wijmo.collections.CollectionView(this.dataSvc.getData(this.countries));
}
}
bootstrap(AppCmp, [DataSvc]);

app.html
<div>
Select a Country: <wj-combo-box [itemsSource]="data" [displayMemberPath]="'country'">
</wj-combo-box>
</div>
<wj-flex-grid [itemsSource]="data" [selectionMode]="'Row'">
<wj-flex-grid-column [header]="'Country'" [binding]="'country'" width="*"></wj-flex-grid-column>
<wj-flex-grid-column [header]="'Sales'" [binding]="'sales'" width="*"></wj-flex-grid-column>
<wj-flex-grid-column [header]="'Expenses'" [binding]="'expenses'" width="*"></wj-flex-grid-column>
<wj-flex-grid-column [header]="'Downloads'" [binding]="'downloads'" width="*"></wj-flex-grid-column>
</wj-flex-grid>
<wj-flex-chart [itemsSource]="data" [bindingX]="'country'" [selectionMode]="'Point'">
<wj-flex-chart-legend [position]="'Bottom'"></wj-flex-chart-legend>
<wj-flex-chart-series [name]="'Sales'" [binding]="'sales'"></wj-flex-chart-series>
<wj-flex-chart-series [name]="'Expenses'" [binding]="'expenses'"></wj-flex-chart-series>
<wj-flex-chart-series [name]="'Downloads'" [binding]="'downloads'"></wj-flex-chart-series>
</wj-flex-chart>

Transcript


Hello Everyone, welcome to the building a dashboard using a shared dared data service with Wijmo and Angular 2. I am Ross Dederer, developer relations at GrapeCity.

Let’s begin by creating a new application in Visual Studio 2015.

I am going to name my project DashboardNg2.

If you haven’t already I encourage you to check out our getting started videos.

Add a new component to our src folder. This will require two files, an app ts and app html file.

Inside App ts import the angular 2 libraries. For this dashboard, we will use a Wijmo input, Wijmo FlexChart, and Wijmo FlexGrid. So let's import those modules as well. Finally, let's import our Data service.

Configure our component decorator selector with app, templateUrl to point to app html and import our CORE_DIRECTIVES. Next, we need to import our Wijmo input directives of combo box, a few from FlexChart, and a few from FlexGrid.

Now let’s build our class and give it a default constructor. To complete the app ts structure, let's assign a root component of AppCmp and expose our Data service to it.

Add a new Typescript class and call it DataSvc. This will be our shared data service.

We need to import an injectable from Angular 2.

Now let’s build our class. Inside our class create a getData function that returns an array. We can use a for loop to complete the model. I am going to give my getData function a simple string parameter to customize the data request.

Back in our AppCmp class let's declare countries as a string. We can declare our data property a type of Wijmo.CollectionView. In our default constructor we need to inject DataSvc as a property type and then assign dataSvc to it.

We need to initialize dataSvc to our parameter from our constructor. Visual Studio is going to point out my error here. Finally, we can instantiate data as a new Wijmo.CollectionView passing it our array from our dataSvc.

Finally, we need to construct our view that will contain our three controls. Lets add a combo box bound to data displaying the country field. Add a FlexGrid bound to data and define each column manually in our markup. Lastly, add a FlexChart bound to data defining each of our three series manually.

Set our default.html page as our start up page.

Last but not least, add our component selector element to our main body.

If we run the application, we can run through our dashboard. As we change the combo box value, the selected item in the grid updates.

If we want to update values in our Grid, our Chart will update automatically.

Thanks for watching. Learn more at Wijmo.com/angular2.


Read more about Angular 2 and other Wijmo controls.