<!DOCTYPE html>
<html>
<head>
<title>Angular 2 ListView With Template by Spring IT</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.5/css/bootstrap.min.css" integrity="sha384-AysaV+vQoT3kOAXZkl02PThvDr8HYKPZhNT5h/CXfBThSRXQ6jW5DO2ekP5ViFdi" crossorigin="anonymous">
<link rel="stylesheet" href="style.css">
<!-- 1. Load libraries -->
<script src="https://unpkg.com/core-js@2.4.1/client/shim.min.js"></script>
<script src="https://unpkg.com/zone.js/dist/zone.js"></script>
<script src="https://unpkg.com/zone.js/dist/long-stack-trace-zone.js"></script>
<script src="https://unpkg.com/reflect-metadata@0.1.3/Reflect.js"></script>
<script src="https://unpkg.com/systemjs@0.19.31/dist/system.js"></script>
<!-- 2. Configure SystemJS -->
<script src="systemjs.config.js"></script>
<script>
System.import('app').catch(function(err){ console.error(err); });
</script>
</head>
<!-- 3. Display the application -->
<body>
<my-app>Loading demo.</my-app>
</body>
</html>
/* Styles go here */
import { Component } from '@angular/core';
import { ListViewComponent } from './listview.component.ts';
@Component({
selector: 'my-app',
template: `<h1>A Angular 4 animation on a component ListView</h1>
<button (click)="lv.hide()">Hide listview</button>
<button (click)="lv.show()">Show listview</button>
<hr>
visibility: {{lv.visibility}}
<hr>
<listview #lv [items]='items'>
<template #headerTemplate>
<div class='header'>I am the most awesome header ever</div></template>
<template #itemTemplate let-item="item">
<div class="item">
<h3>{{item.name}}</h3>
<h4>{{item.description}}</h4>
</div>
</template>
</listview>`
})
export class AppComponent {
private items = [{
name: 'Blup',
description: 'Nemo says blup'
},{
name: 'FooBar',
description: 'foobar is awesome'
}]
}
/*
Copyright 2016 Google Inc. All Rights Reserved.
Use of this source code is governed by an MIT-style license that
can be found in the LICENSE file at http://angular.io/license
*/
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { AppComponent } from './app.component';
import { ListViewComponent } from './listview.component.ts';
@NgModule({
imports: [BrowserModule, FormsModule, ReactiveFormsModule,BrowserAnimationsModule],
declarations: [AppComponent, ListViewComponent],
bootstrap: [AppComponent]
})
export class AppModule {}
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppModule } from './app.module';
platformBrowserDynamic().bootstrapModule(AppModule);
(function(global) {
var ngVer = '@4.2.2'; // lock in the angular package version; do not let it float to current!
//map tells the System loader where to look for things
var map = {
'app': 'app',
'@angular': 'https://unpkg.com/@angular', // sufficient if we didn't pin the version
'angular2-in-memory-web-api': 'https://unpkg.com/angular2-in-memory-web-api', // get latest
'rxjs': 'https://unpkg.com/rxjs@5.0.0-beta.6',
'ts': 'https://unpkg.com/plugin-typescript@4.0.10/lib/plugin.js',
'typescript': 'https://unpkg.com/typescript@2.1.1/lib/typescript.js',
'@angular/platform-browser/animations': 'https://unpkg.com/@angular/platform-browser@4.2.2/bundles/platform-browser-animations.umd.js',
'@angular/animations/browser': 'https://unpkg.com/@angular/animations@4.2.2/bundles/animations-browser.umd.js',
};
//packages tells the System loader how to load when no filename and/or no extension
var packages = {
'app': { main: 'main.ts', defaultExtension: 'ts' },
'rxjs': { defaultExtension: 'js' },
'angular2-in-memory-web-api': { main: 'index.js', defaultExtension: 'js' },
};
var ngPackageNames = [
'common',
'compiler',
'animations',
'core',
'router',
'http',
'forms',
'platform-browser',
'platform-browser-dynamic',
'upgrade',
];
// Add map entries for each angular package
// only because we're pinning the version with `ngVer`.
ngPackageNames.forEach(function(pkgName) {
map['@angular/'+pkgName] = 'https://unpkg.com/@angular/' + pkgName + ngVer;
});
// Add package entries for angular packages
ngPackageNames.forEach(function(pkgName) {
// Bundled (~40 requests):
packages['@angular/'+pkgName] = { main: '/bundles/' + pkgName + '.umd.js', defaultExtension: 'js' };
// Individual files (~300 requests):
//packages['@angular/'+pkgName] = { main: 'index.js', defaultExtension: 'js' };
});
var config = {
// DEMO ONLY! REAL CODE SHOULD NOT TRANSPILE IN THE BROWSER
transpiler: 'ts',
typescriptOptions: {
tsconfig: true
},
meta: {
'typescript': {
"exports": "ts"
}
},
map: map,
packages: packages
};
System.config(config);
})(this);
/*
Copyright 2016 Google Inc. All Rights Reserved.
Use of this source code is governed by an MIT-style license that
can be found in the LICENSE file at http://angular.io/license
*/
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": false,
"noImplicitAny": true,
"suppressImplicitAnyIndexErrors": true
}
}
import { Component, ContentChild, TemplateRef, Input } from '@angular/core';
import { animate, state, trigger, transition, style } from '@angular/animations';
@Component({
selector: 'listview',
template: `
<ng-template [ngTemplateOutlet]="headerTemplate"></ng-template>
<div class='items' *ngFor="let item of items">
<ng-template [ngTemplateOutlet]="itemTemplate" [ngOutletContext]="{item: item}" ></ng-template>
</div>`,
styles: [`
:host{
position: relative;
width: 400px;
background-color: #eee;
display:block;
}
/deep/ .header{
height: 20px;
line-height: 20px;
background-color: #ddd;
}
/deep/ .items .item{
border-bottom: 1px solid black;
}
/deep/ .items:last-child .item{
border-bottom: 0px;
}`],
host: {
'[@visibilityChanged]': 'visibility'
},
animations: [
trigger('visibilityChanged',
[
state('visible', style({ left: '0' })),
state('hidden', style({ left: '-400px' })),
state('void', style({ left: '-400px' })),
transition('visible => hidden', animate(300)),
transition('hidden => visible', animate(300)),
transition('void => visible', animate(300))
])
]
})
export class ListViewComponent {
@ContentChild('headerTemplate',{read: TemplateRef}) headerTemplate:TemplateRef;
@ContentChild('itemTemplate',{read: TemplateRef}) itemTemplate:TemplateRef;
@Input() items: Array<any> = [];
private hidden:string="hidden";
private visible:string="visible";
@Input() visibility:string = this.visible; //this will trigger the component to animate from void => visible
hide():void{
this.visibility = this.hidden;
}
show():void{
this.visibility = this.visible;
}
}
/*
Copyright 2016 Google Inc. All Rights Reserved.
Use of this source code is governed by an MIT-style license that
can be found in the LICENSE file at http://angular.io/license
*/