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 #1274

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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,5 @@ TODO.md
.nx/cache
.nx/workspace-data

.cursorrules
.cursorrules
.qodo
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ChangeDetectionStrategy, Component, signal } from '@angular/core';
import { ChangeDetectionStrategy, Component, model } from '@angular/core';

@Component({
selector: 'app-expandable-card',
Expand Down Expand Up @@ -50,5 +50,5 @@ import { ChangeDetectionStrategy, Component, signal } from '@angular/core';
},
})
export class ExpandableCard {
public isExpanded = signal(false);
public isExpanded = model(false);
}
17 changes: 14 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 [(isExpanded)]="isExpanded">
<div title>Load Post</div>
<div>
@if (postRessource.isLoading()) {
Expand All @@ -36,8 +37,18 @@ interface Post {
imports: [ExpandableCard],
})
export class Page2 {
protected readonly ResourceStatus = ResourceStatus;

public postRessource = httpResource<Post[]>(
'https://jsonplaceholder.typicode.com/posts',
() => {
return this.isExpanded()
? 'https://jsonplaceholder.typicode.com/posts'
: undefined;
},
{
defaultValue: [],
},
);
protected readonly ResourceStatus = ResourceStatus;

isExpanded = signal(false);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can use viewChild or exportAs to access a child property as well. It creates less boilerplate, but your solution is working

}
Loading