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

Added Context snippet for Angular #179

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
@@ -0,0 +1,13 @@
<div>
<h1>Welcome back, {{ user.username }}</h1>
<ng-template
*ngTemplateOutlet="UserContext; context: { user: user, updateUsername }"
></ng-template>
</div>

<ng-template #UserContext let-user="user">
<app-user-profile
[user]="user"
[updateUsername]="updateUsername"
></app-user-profile>
</ng-template>
17 changes: 17 additions & 0 deletions content/4-component-composition/5-context/angular/app.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Component } from "@angular/core";

@Component({
selector: "app-root",
templateUrl: "./app.component.html",
styleUrls: ["./app.component.scss"],
})
export class AppComponent {
public user = {
id: 1,
username: "unicorn42",
email: "[email protected]",
};
public updateUsername = (name) => {
this.user.username = name;
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Component, Input } from "@angular/core";

@Component({
selector: "app-user-profile",
template: `
<div>
<h2>My Profile</h2>
<p>Username: {{ user.username }}</p>
<p>Email: {{ user.email }}</p>
<button (click)="updateUsername('Jane')">Update username to Jane</button>
</div>
`,
})
export default class MyUserProfileComponent {
@Input() user;
@Input() updateUsername;
}
Loading