Created
November 29, 2017 01:23
-
-
Save ryansutc/c91a7134f3bd3fd01d3a845b6bdf8aeb to your computer and use it in GitHub Desktop.
Request to Web Service for Data
This file contains 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
@Component({ | |
templateUrl: 'freeroom-results.html', | |
}) | |
export class FreeRoomResultsPage { | |
//public rooms: string[] = new Array(); | |
rooms: any; | |
public day: Date = new Date(); | |
icon: string; | |
constructor(public navCtrl: NavController, public navParams: NavParams, public http: Http){ | |
this.icon = 'ion-android-calendar'; | |
} | |
ngOnInit(): void { | |
this.rooms = []; | |
let today = this.GetDayOfWeekString(this.day.getDay()); | |
let campus = this.navParams.get('campus'); | |
let building = this.navParams.get('building'); | |
let roomtype = this.navParams.get('roomtype'); | |
let timeparse = this.navParams.get('starttime').split(':'); | |
let starttime = timeparse[0]+ "" + timeparse[1]; | |
let myday = this.GetDayOfWeekString(this.day.getDay()); | |
let url = 'http://nsccsucks.xyz/FreeRoomUntil/roomData/' + campus + '/' | |
+ building + '/' + starttime + '/' + myday + '/' + roomtype; | |
//Get returns results in form of an observable, map converts to JSON, subscribe allows access/iteration | |
////http://nsccsucks.xyz/FreeRoomUntil/roomData/INSTI/ITC/0800/Wednesday | |
this.http.get(url).map(res => res.json()).subscribe(data => { | |
for (let room of data) { | |
let roomResults = { | |
Room: room.Room, | |
AvailUntil: room.AvailUntil, | |
AvailMsg: this.GetTimeLengthMsg(this.navParams.get('starttime'), room.AvailUntil) | |
}; | |
this.rooms.push(roomResults); | |
} | |
//this.rooms = data; | |
//console.log(this.rooms); | |
}, | |
err => { | |
console.log("Oops!"); | |
}); | |
/* | |
this.http.get(url) | |
.toPromise() | |
.then(response => response.json().data.Room as string[]) | |
.catch(this.handleError) | |
*/ | |
} | |
private handleError(error: any): Promise { | |
console.error('An error occurred', error); // for demo purposes only | |
return Promise.reject(error.message || error); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment