-
-
Save spongessuck/8d14e309da47cf45f7d6ceae1aecd111 to your computer and use it in GitHub Desktop.
ng2-resource-rest troubleshoot
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
import { Component, | |
OnInit, | |
OnDestroy } from '@angular/core'; | |
import { ActivatedRoute } from '@angular/router'; | |
import { SessionResource } from '../../shared/resources/'; | |
import { Subscription } from 'rxjs'; | |
@Component({ | |
selector: 'app-course-calendar', | |
template: ` | |
... | |
`, | |
providers: [SessionResource] | |
}) | |
export class CourseCalendarComponent implements OnInit, OnDestroy { | |
items: any; | |
private sub: Subscription; | |
constructor( | |
private resource: SessionResource, | |
private route: ActivatedRoute | |
) { } | |
ngOnInit() { | |
this.sub = this.route | |
.params | |
.subscribe(params => { | |
this.items = this.resource.query({ courseID: params['id'] }); | |
}); | |
} | |
ngOnDestroy() { | |
this.sub.unsubscribe(); | |
} | |
} |
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
import { Component, | |
OnInit, | |
OnDestroy } from '@angular/core'; | |
import { ActivatedRoute } from '@angular/router'; | |
import { SessionResource } from '../../shared/resources/'; | |
import { Subscription } from 'rxjs'; | |
@Component({ | |
selector: 'app-sequence-calendar', | |
template: ` | |
... | |
`, | |
providers: [SessionResource] | |
}) | |
export class SequenceCalendarComponent implements OnInit, OnDestroy { | |
items: any; | |
private sub: Subscription; | |
constructor( | |
private resource: SessionResource, | |
private route: ActivatedRoute | |
) { } | |
ngOnInit() { | |
this.sub = this.route | |
.params | |
.subscribe(params => { | |
this.items = this.resource.query({ seqID: params['id'] }); | |
}); | |
} | |
ngOnDestroy() { | |
this.sub.unsubscribe(); | |
} | |
} |
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
import { Injectable } from '@angular/core'; | |
import { Http } from '@angular/http'; | |
import { Resource, | |
ResourceParams } from 'ng2-resource-rest'; | |
function resourceParamsWithPathType(pathType: string) { | |
return { | |
url: ( | |
REDACTED_API_URL + pathType + '/{id}', | |
removeTrailingSlash: false, | |
data: { | |
acadYear: 2017 | |
} | |
}; | |
} | |
@Injectable() | |
@ResourceParams(resourceParamsWithPathType('session')) | |
export class SessionResource extends Resource { | |
constructor(protected http: Http) { | |
super(http); | |
} | |
query(data?, callback?) { | |
return super.query(data, function(result) { | |
result = result.sort(function(a, b) { | |
return Date.parse(a.start) - Date.parse(b.start); | |
}); | |
if (callback) { | |
callback(result); | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment