-
Notifications
You must be signed in to change notification settings - Fork 93
Add support for Angular bindings API with twoWayBinding #547
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
Merged
timdeschryver
merged 7 commits into
main
from
copilot/fix-e93f4325-fc7e-4d7a-b6a8-9ff4df8eb8d9
Sep 29, 2025
+389
−5
Merged
Changes from 3 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
b815a18
Initial plan
Copilot 6a6d336
Add support for Angular v20 bindings API
Copilot 3dca2ea
Add documentation for Angular v20 bindings API
Copilot ec079c2
Address review feedback: Remove re-exports, enable mixed usage with w…
Copilot 39fe933
Add twoWayBinding support and writable signal test cases
Copilot 04e96a2
manual tweaks
timdeschryver c44861e
add tests for the example component
timdeschryver File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
36 changes: 36 additions & 0 deletions
36
apps/example-app/src/app/examples/23-bindings-api.component.ts
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { Component, computed, input, model, numberAttribute, output } from '@angular/core'; | ||
import { FormsModule } from '@angular/forms'; | ||
|
||
@Component({ | ||
selector: 'atl-bindings-api-example', | ||
template: ` | ||
<div data-testid="input-value">{{ greetings() }} {{ name() }} of {{ age() }} years old</div> | ||
<div data-testid="computed-value">{{ greetingMessage() }}</div> | ||
<button data-testid="submit-button" (click)="submitName()">Submit</button> | ||
<button data-testid="increment-button" (click)="incrementAge()">Increment Age</button> | ||
<input type="text" data-testid="name-input" [(ngModel)]="name" /> | ||
<div data-testid="current-age">Current age: {{ age() }}</div> | ||
`, | ||
standalone: true, | ||
imports: [FormsModule], | ||
}) | ||
export class BindingsApiExampleComponent { | ||
greetings = input<string>('', { | ||
alias: 'greeting', | ||
}); | ||
age = input.required<number, string>({ transform: numberAttribute }); | ||
name = model.required<string>(); | ||
submitValue = output<string>(); | ||
ageChanged = output<number>(); | ||
|
||
greetingMessage = computed(() => `${this.greetings()} ${this.name()} of ${this.age()} years old`); | ||
|
||
submitName() { | ||
this.submitValue.emit(this.name()); | ||
} | ||
|
||
incrementAge() { | ||
const newAge = this.age() + 1; | ||
this.ageChanged.emit(newAge); | ||
} | ||
} |
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { Component, input, output } from '@angular/core'; | ||
import { render, screen, inputBinding, outputBinding } from '../src/public_api'; | ||
|
||
describe('ATL Bindings API Support', () => { | ||
@Component({ | ||
selector: 'atl-bindings-test', | ||
template: ` | ||
<div data-testid="value">{{ value() }}</div> | ||
<div data-testid="greeting">{{ greeting() }}</div> | ||
<button data-testid="emit-button" (click)="clicked.emit('clicked: ' + value())">Click me</button> | ||
`, | ||
standalone: true, | ||
}) | ||
class BindingsTestComponent { | ||
value = input<string>('default'); | ||
greeting = input<string>('hello', { alias: 'greet' }); | ||
clicked = output<string>(); | ||
} | ||
|
||
it('should support inputBinding for regular inputs', async () => { | ||
timdeschryver marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
await render(BindingsTestComponent, { | ||
bindings: [inputBinding('value', () => 'test-value'), inputBinding('greet', () => 'hi there')], | ||
}); | ||
|
||
expect(screen.getByTestId('value')).toHaveTextContent('test-value'); | ||
expect(screen.getByTestId('greeting')).toHaveTextContent('hi there'); | ||
}); | ||
|
||
it('should support outputBinding for outputs', async () => { | ||
const clickHandler = jest.fn(); | ||
|
||
await render(BindingsTestComponent, { | ||
bindings: [inputBinding('value', () => 'bound-value'), outputBinding('clicked', clickHandler)], | ||
}); | ||
|
||
const button = screen.getByTestId('emit-button'); | ||
button.click(); | ||
|
||
expect(clickHandler).toHaveBeenCalledWith('clicked: bound-value'); | ||
}); | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.