Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/363.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
Javascript 我需要帮助。 <ion-header > <ion-navbar id="navbar" class="toolbar-background"> <ion-toolbar> <_Javascript_Select_Ionic2_Angular2 Services - Fatal编程技术网

Javascript 我需要帮助。 <ion-header > <ion-navbar id="navbar" class="toolbar-background"> <ion-toolbar> <

Javascript 我需要帮助。 <ion-header > <ion-navbar id="navbar" class="toolbar-background"> <ion-toolbar> <,javascript,select,ionic2,angular2-services,Javascript,Select,Ionic2,Angular2 Services,我需要帮助。 <ion-header > <ion-navbar id="navbar" class="toolbar-background"> <ion-toolbar> <ion-title id="title"><p><span class="title">MyTitle</span>{{selectedCity}}</p></ion-title>

我需要帮助。
<ion-header > 
   <ion-navbar id="navbar" class="toolbar-background">   

  <ion-toolbar>

        <ion-title id="title"><p><span class="title">MyTitle</span>{{selectedCity}}</p></ion-title> 
        <ion-buttons end>

<ion-icon id="icon" name="heart">Change City</ion-icon>

                <ion-select id="select" [(ngModel)]="selectedCity" (ionChange)="changeCity(selectedCity)" >
                        <ion-option value="New York">New York</ion-option>
                        <ion-option value="Philadelphia">Philadelphia</ion-option>
                        <ion-option value="Boston">Boston</ion-option>
                        <ion-option value="L.A.">L.A.</ion-option>
                        <ion-option value="San Francisco">San Francisco</ion-option>

               </ion-select>

         </ion-buttons>

      </ion-toolbar> 
       </ion-navbar>

   </ion-header> 

  <ion-content id="content">

     <ion-card id="card" *ngFor="let event of listOfEvents" >         


       //Code for post info goes here on this card 

    </ion-card>

</ion-content >
import { Injectable } from '@angular/core';

declare var OnymosUtil:any;

@Injectable()
export class getPosts {
constructor(){}


     listOfEvents: Array<any> = []; 

     newCity: string; 


/*Below is the service that gets the posts to populate the feed. I thought I could pass it a variable that could determine reload or not*/ 

getPosts(selectedCity,reloadPg){



   /*should there be a page refresh here?  */

if(reloadPg == true){
window.location.reload();
}


this.newCity = selectedCity; 

let that = this; 

    OnymosUtil.getData(

        '/events/' + this.newCity ,    

        function successCallback (listOfEventsObject) {

                for (var x in listOfEventsObject) {

                   that.listOfEvents.push(listOfEventsObject[x]);
                }




        },

        function failureCallback (error) {
            alert(error);
        },

        {

            orderByField:'createdTime',
        }); 

    }//end getPosts
import { Component } from '@angular/core';
import { NavController, ModalController } from 'ionic-angular';
import { LoadingController } from 'ionic-angular';
import { getPosts } from '../../services/getPosts.service';


 declare var OnymosUtil:any;



@Component({
  selector: 'page-home',
  templateUrl: 'home.html',
  providers: [getPosts]
})
export class Home {

     listOfEvents: Array<any> = []; 

     selectedCity: string = 'New York';

     reloadPg: boolean; 





 constructor (public navCtrl: NavController, public modalCtrl: ModalController, public loading: LoadingController, public getPostSrvc: getPosts) {



getPostSrvc.getPosts(this.selectedCity); /*this populates the feed with the default city's posts from New York*/

this.listOfEvents = getPostSrvc.listOfEvents; 

}// end of constructor

/*here is where I tried to use a reload:*/

changeCity(selectedCity){

this.reloadPg = true; 

           this.getPostSrvc.getPosts(selectedCity, this.reloadPg);

      };

}//close class 
import {Component, NgModule, VERSION, onInit} from '@angular/core'
import {BrowserModule} from '@angular/platform-browser'

const events = [
  {
    city: 'New York',
    events: [
      {
        title: 'Comedy in Broadway',
        description: 'Get ready to pee your pants laughing'
      },
      {
        title: 'Puertorican Day Parad',
        description: 'Lots of traffic, loud music, great party!'
      }
    ]
  },
  {
    city: 'Chicago',
    events: [
      {
        title: 'Al Capone Memorial',
        description: 'Go back to the days of prohibition and how the gangsters ruled the city'
      },
      {
        title: 'White Sox vs Bears',
        description: 'Which is worse?'
      }
    ]
  }
];


@Component({
  selector: 'my-app',
  template: `
    <div>
      <h2>City: {{ currentEvent.city }}</h2>
      <ul>
        <li *ngFor="let e of currentEvent.events">
          <h3> {{ e.title }} </h3>
          <div>
            {{ e.description }}
          </div>
        </li>
      </ul>
    </div>
    <div>
      <button (click)="changeCity('Chicago')">View Chicago Events</button>
      <button (click)="changeCity('New York')">View New York Events</button>
    </div>
  `,
})
export class App implements OnInit{
  name:string;
  currentEvent;
  constructor() {
    this.name = `Angular! v${VERSION.full}`
  }

  ngOnInit() {
    this.currentEvent = events.filter(event => event.city === 'New York')[0];
    console.log(this.currentEvent);
  }

  changeCity(city) {
    this.currentEvent = events.filter(event => event.city === city)[0];
  }
}

@NgModule({
  imports: [ BrowserModule ],
  declarations: [ App ],
  bootstrap: [ App ]
})
export class AppModule {}
import { Injectable } from '@angular/core';
import { Http } from '@angular/http';
import 'rxjs/add/operator/toPromise';

@Injectable()
export class AppService {
  constructor(private http: Http) {}

  getAllEvents(): Promise<any>{
    return this.http.get('dummy_data.json').toPromise();
  }

  getEventsForCity(city): Promise<Array<any>> {
    let data = [];
    return new Promise((resolve, reject) => {
      this.getAllEvents().then(events => {
        events = events.json();
        data = events.filter(event => event.city === city)[0];
        if(!data) {
          return reject();
        }
        console.log(data);
        resolve(data):
      });
    });
  }
}
//our root app component
import {Component, NgModule, VERSION, onInit} from '@angular/core'
import { HttpModule } from '@angular/http';
import {BrowserModule} from '@angular/platform-browser'
import { AppService } from './app.service';

@Component({
  selector: 'my-app',
  template: `
    <div>
      <h2>City: {{ currentEvent.city }}</h2>
      <ul>
        <li *ngFor="let e of currentEvent.events">
          <h3> {{ e.title }} </h3>
          <div>
            {{ e.description }}
          </div>
        </li>
      </ul>
    </div>
    <div>
      <button (click)="changeCity('Chicago')">View Chicago Events</button>
      <button (click)="changeCity('New York')">View New York Events</button>
    </div>
  `,
})
export class App implements OnInit{
  currentEvent = {
    currentCity: '',
    events: []
  };
  constructor(private appSvc: AppService) {

  }

  ngOnInit() {
    this.appSvc.getAllEvents()
      .then(events => {
        events = events.json();
        this.currentEvent = events.filter(event => event.city === 'New York')[0];
      });
  }

  changeCity(city) {
    this.appSvc.getEventsForCity(city).then(events => this.currentEvent = events);
  }
}

@NgModule({
  imports: [ BrowserModule, HttpModule ],
  declarations: [ App ],
  bootstrap: [ App ],
  providers: [ AppService ]
})
export class AppModule {}