Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Answer: 59 #1267

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import { ChangeDetectionStrategy, Component, signal } from '@angular/core';
import {
ChangeDetectionStrategy,
Component,
output,
signal,
} from '@angular/core';

@Component({
selector: 'app-expandable-card',
template: `
<button
class="text-fg-subtle hover:bg-button-secondary-bg-hover active:bg-button-secondary-bg-active focus:outline-button-border-highlight flex w-fit items-center gap-1 py-2 focus:outline focus:outline-2 focus:outline-offset-1"
(click)="isExpanded.set(!isExpanded())"
(click)="expandedChange()"
data-cy="expandable-panel-toggle">
@if (isExpanded()) {
<svg
Expand Down Expand Up @@ -51,4 +56,10 @@ import { ChangeDetectionStrategy, Component, signal } from '@angular/core';
})
export class ExpandableCard {
public isExpanded = signal(false);
expanded = output<boolean>();

expandedChange = () => {
this.isExpanded.set(!this.isExpanded());
this.expanded.emit(this.isExpanded());
};
}
10 changes: 7 additions & 3 deletions apps/angular/59-content-projection-defer/src/app/page-2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
ChangeDetectionStrategy,
Component,
ResourceStatus,
signal,
} from '@angular/core';
import { ExpandableCard } from './expandable-card';

Expand All @@ -17,7 +18,7 @@ interface Post {
selector: 'app-page-2',
template: `
page2
<app-expandable-card>
<app-expandable-card (expanded)="triggerFetch.set($event)">
<div title>Load Post</div>
<div>
@if (postResource.isLoading()) {
Expand All @@ -36,8 +37,11 @@ interface Post {
imports: [ExpandableCard],
})
export class Page2 {
public postResource = httpResource<Post[]>(
'https://jsonplaceholder.typicode.com/posts',
protected triggerFetch = signal(false);
public postResource = httpResource<Post[]>(() =>
!this.triggerFetch()
? undefined
: 'https://jsonplaceholder.typicode.com/posts',
);
protected readonly ResourceStatus = ResourceStatus;
}