src/lib/src/directives/resource-outlet.ts
Loads and renders data from given URL. Support navigation via _self
.
For more complicated use-cases, see ResourceDataOfDirective.
<!-- To bind to browser location, provide apiLocation as component property and use its url -->
<resource-outlet [(src)]="apiLocation.url"></resource-outlet>
<!-- To view referenced content, use link href -->
<resource-outlet [(src)]="data._links?.content?.href"></resource-outlet>
providers |
ResourceData
()
()
|
selector | resource-outlet |
template |
|
Properties |
|
Methods |
Inputs |
Outputs |
Accessors |
constructor(resource: ResourceData)
|
||||||||
Defined in src/lib/src/directives/resource-outlet.ts:33
|
||||||||
Parameters :
|
src
|
Type: |
Defined in src/lib/src/directives/resource-outlet.ts:51
|
srcChange
|
$event type: EventEmitter
|
Defined in src/lib/src/directives/resource-outlet.ts:32
|
ngOnDestroy |
ngOnDestroy()
|
Defined in src/lib/src/directives/resource-outlet.ts:42
|
Returns :
void
|
ngOnInit |
ngOnInit()
|
Defined in src/lib/src/directives/resource-outlet.ts:38
|
Returns :
void
|
Readonly Public resource |
resource:
|
Type : ResourceData
|
Decorators : Self
|
Defined in src/lib/src/directives/resource-outlet.ts:35
|
src |
getsrc()
|
Defined in src/lib/src/directives/resource-outlet.ts:46
|
setsrc(value: string)
|
Defined in src/lib/src/directives/resource-outlet.ts:51
|
import { Component, EventEmitter, Input, OnDestroy, OnInit, Output, Self } from '@angular/core';
import { Subscription } from 'rxjs';
import { ResourceData, resourceDataNavigableRef } from '../resource-data';
import { topLevelNavigableRef } from '../navigable';
import { ResourceDataOfDirective } from './resource-data-of';
/**
* Loads and renders data from given URL. Support navigation via `_self`.
*
* For more complicated use-cases, see {@link ResourceDataOfDirective}.
*
* @example
* <!-- To bind to browser location, provide apiLocation as component property and use its url -->
* <resource-outlet [(src)]="apiLocation.url"></resource-outlet>
*
* <!-- To view referenced content, use link href -->
* <resource-outlet [(src)]="data._links?.content?.href"></resource-outlet>
*/
@Component({
selector: 'resource-outlet',
template: '<resource-view [data]="resource.data"></resource-view>',
providers: [
ResourceData,
resourceDataNavigableRef(),
topLevelNavigableRef()
]
})
export class ResourceOutletComponent implements OnInit, OnDestroy {
@Output()
public readonly srcChange = new EventEmitter<string>();
private subscription = Subscription.EMPTY;
constructor(@Self() public readonly resource: ResourceData) {
}
ngOnInit(): void {
this.subscription = this.resource.urlChange.subscribe((value: string) => this.srcChange.emit(value));
}
ngOnDestroy(): void {
this.subscription.unsubscribe();
}
get src(): string {
return this.resource.url;
}
@Input()
set src(value: string) {
this.resource.url = value;
}
}