Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs Can';t显示从Firebase检索到的数据_Angularjs_Angular - Fatal编程技术网

Angularjs Can';t显示从Firebase检索到的数据

Angularjs Can';t显示从Firebase检索到的数据,angularjs,angular,Angularjs,Angular,我正在创建一个关于山脉的angular2应用程序。我正在尝试从Firebase检索并显示一些数据。 我拥有的文件如下(我删除了样板代码) 山脉列表.component.ts import {Pipe, PipeTransform} from 'angular2/core'; import {MapToIterable} from "./mypipe-pipe"; @Component({ selector: 'my-mountain-list', template: `

我正在创建一个关于山脉的angular2应用程序。我正在尝试从Firebase检索并显示一些数据。 我拥有的文件如下(我删除了样板代码)

山脉列表.component.ts

import {Pipe, PipeTransform} from 'angular2/core';
import {MapToIterable} from "./mypipe-pipe";

@Component({
    selector: 'my-mountain-list',
    template: `
    <h1>ALL THE MOUNTAINS</h1>
        <button (click)="onGetMountain()">Get Mountains</button>
        <br>
        <ul>
            <li *ngFor="#item of mountains | MapToIterable" (click)="onSelect(item)">
                This is the key {{item.key}} and this is the value {{item.value}}<br>
            </li>
        </ul>
    `,
    pipes: [MapToIterable]
})

export class MountainListComponent implements OnInit {
    ngOnInit(): any {
        this.mountains = this._mountainService.getAllMountains();
    }
}
import {Pipe} from "angular2/core";
import {Mountain} from "./mountain";

@Pipe({
  name: 'MapToIterable'
})
export class MapToIterable {
  transform(dict: Mountain[]): any {
    var a = [];
    for (var key in dict) {
      if (dict.hasOwnProperty(key)) {
        a.push({ key: key, val: dict[key] });
      }
    }
    return a;
  }
}
import {Injectable} from "angular2/core";
import {Http, Headers} from "angular2/http";
import 'rxjs/Rx';
import {Observable} from "rxjs/Observable";
import {Mountain} from "../protected/mountain/mountain";

@Injectable()
export class MountainDataService {
    constructor(private _http: Http) {}

    getAllMountains(): Observable<any> 
    {
        const token = localStorage.getItem('token') !== null ? '?auth=' + localStorage.getItem('token') : '';
        return this._http.get('https://xxxxx-xxxx-xxxx.firebaseio.com/users/data.json' + token)
            .map(response => response.json());

    }
}
mountain.service.ts

import {Pipe, PipeTransform} from 'angular2/core';
import {MapToIterable} from "./mypipe-pipe";

@Component({
    selector: 'my-mountain-list',
    template: `
    <h1>ALL THE MOUNTAINS</h1>
        <button (click)="onGetMountain()">Get Mountains</button>
        <br>
        <ul>
            <li *ngFor="#item of mountains | MapToIterable" (click)="onSelect(item)">
                This is the key {{item.key}} and this is the value {{item.value}}<br>
            </li>
        </ul>
    `,
    pipes: [MapToIterable]
})

export class MountainListComponent implements OnInit {
    ngOnInit(): any {
        this.mountains = this._mountainService.getAllMountains();
    }
}
import {Pipe} from "angular2/core";
import {Mountain} from "./mountain";

@Pipe({
  name: 'MapToIterable'
})
export class MapToIterable {
  transform(dict: Mountain[]): any {
    var a = [];
    for (var key in dict) {
      if (dict.hasOwnProperty(key)) {
        a.push({ key: key, val: dict[key] });
      }
    }
    return a;
  }
}
import {Injectable} from "angular2/core";
import {Http, Headers} from "angular2/http";
import 'rxjs/Rx';
import {Observable} from "rxjs/Observable";
import {Mountain} from "../protected/mountain/mountain";

@Injectable()
export class MountainDataService {
    constructor(private _http: Http) {}

    getAllMountains(): Observable<any> 
    {
        const token = localStorage.getItem('token') !== null ? '?auth=' + localStorage.getItem('token') : '';
        return this._http.get('https://xxxxx-xxxx-xxxx.firebaseio.com/users/data.json' + token)
            .map(response => response.json());

    }
}

仅供参考:我确信getAllMountains()会从Firebase检索数据

如果你记录来自_http.get?@TimK的响应,你会得到什么?这篇文章——提到必须导入'rxjs/add/operator/map'来获取观测值上的map()方法。