Last active
September 20, 2016 14:53
-
-
Save s-o-r-o-u-s-h/3138059bb71080b8e9de to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //datatable.pipe.ts | |
| import {Pipe} from "angular2/core"; | |
| @Pipe({name: "iterateObject", pure: false}) | |
| export class IterateObjectPipe { | |
| transform(value:any, args:string[] = null):any { | |
| return Object.keys(value).map(key => value[key]); | |
| } | |
| } | |
| //app.component.ts | |
| import {Component,OnInit} from "angular2/core"; | |
| import {Datatable} from "../interfaces/datatable"; | |
| import {DatatableService} from "./datatable.service"; | |
| import {IterateObjectPipe} from "./datatable.pipe"; | |
| @Component({ | |
| selector: 'app', | |
| templateUrl: 'app/main/app.component.html', | |
| providers: [DatatableService], | |
| pipes: [IterateObjectPipe] | |
| }) | |
| export class AppComponent implements OnInit{ | |
| public init:Datatable; | |
| constructor(public _DatatableService: DatatableService){} | |
| ngOnInit():any { | |
| this._DatatableService.getDatatables().subscribe(res=>{this.init = res}); | |
| } | |
| } | |
| //datatable.service.ts | |
| import {Injectable} from "angular2/core"; | |
| import {Http} from "angular2/http"; | |
| import "rxjs/add/operator/map"; | |
| @Injectable() | |
| export class DatatableService { | |
| getDatatables() { | |
| return this._http.get('init.json').map(res => res.json()); | |
| } | |
| constructor(private _http: Http){} | |
| } | |
| //app.component.html | |
| <div class="col-xs-12 col-sm-6 col-md-3 modules-item" *ngFor="#module of init|iterateObject"> | |
| <h4 class="text-center">test</h4> | |
| </div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
TypeError: Cannot convert undefined or null to object in [init|iterateObject in AppComponent@6:62]