Thanks to visit codestin.com
Credit goes to github.com

Skip to content

feat(compiler): support void and exponentiation operators in templates #59894

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

Closed
wants to merge 2 commits into from

Conversation

mmalerba
Copy link
Contributor

@mmalerba mmalerba commented Feb 8, 2025

Add support for the void operator in templates and host bindings.

This is useful when binding a listener that may return false and
unintentionally prevent the default event behavior.

Ex:

@Directive({
  host: { '(mousedown)': 'void handleMousedown()' }
})

Also adds support for the exponentiation (**) operator

Ex:

@Component {
  template: '{{2 ** 3}}'
}

BREAKING CHANGE: void in an expression now refers to the operator

Previously an expression in the template like {{void}} referred to a
property on the component class. After this change it now refers to the
void operator, which would make the above example invalid. If you have
existing expressions that need to refer to a property named void,
change the expression to use this.void instead: {{this.void}}.

@mmalerba mmalerba requested a review from crisbeto February 8, 2025 18:50
@angular-robot angular-robot bot added detected: feature PR contains a feature commit area: compiler Issues related to `ngc`, Angular's template compiler labels Feb 8, 2025
@ngbot ngbot bot added this to the Backlog milestone Feb 8, 2025
@mmalerba mmalerba force-pushed the void-op branch 3 times, most recently from d7f461c to a797765 Compare February 10, 2025 23:29
@mmalerba mmalerba changed the title feat(compiler): support void operator in templates feat(compiler): support void and exponentiation operators in templates Feb 11, 2025
@mmalerba mmalerba marked this pull request as ready for review February 11, 2025 00:28
@mmalerba mmalerba force-pushed the void-op branch 4 times, most recently from d62bfeb to 7fc4efe Compare February 11, 2025 21:09
Copy link
Member

@crisbeto crisbeto left a comment

Choose a reason for hiding this comment

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

Overall LGTM. Given that void is a new kind of expression, I think we need a few language service tests as well. E.g. that quick info and going to definition works when targeting the expression.

@mmalerba
Copy link
Contributor Author

Added the recommended tests

@angular-robot angular-robot bot requested a review from crisbeto February 20, 2025 16:43
Add support for the `void` operator in templates and host bindings.

This is useful when binding a listener that may return `false` and
unintentionally prevent the default event behavior.

Ex:
```
@directive({
  host: { '(mousedown)': 'void handleMousedown()' }
})
```

BREAKING CHANGE: `void` in an expression now refers to the operator

Previously an expression in the template like `{{void}}` referred to a
property on the component class. After this change it now refers to the
`void` operator, which would make the above example invalid. If you have
existing expressions that need to refer to a property named `void`,
change the expression to use `this.void` instead: `{{this.void}}`.
Adds support for the exponentiation (`**`) operator in templates

Ex:
```
@component {
  template: '{{2 ** 3}}'
}
```
@angular-robot angular-robot bot added the detected: breaking change PR contains a commit with a breaking change label Feb 20, 2025
@mmalerba mmalerba added the target: major This PR is targeted for the next major release label Feb 20, 2025
@mmalerba mmalerba removed the request for review from crisbeto February 20, 2025 20:47
@mmalerba mmalerba added target: major This PR is targeted for the next major release action: merge The PR is ready for merge by the caretaker and removed target: major This PR is targeted for the next major release labels Feb 20, 2025
@kirjs
Copy link
Contributor

kirjs commented Feb 25, 2025

This PR was merged into the repository by commit f2d5cf7.

The changes were merged into the following branches: main

@kirjs kirjs closed this in 0361c2d Feb 25, 2025
kirjs pushed a commit that referenced this pull request Feb 25, 2025
Adds support for the exponentiation (`**`) operator in templates

Ex:
```
@component {
  template: '{{2 ** 3}}'
}
```

PR Close #59894
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Mar 28, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker area: compiler Issues related to `ngc`, Angular's template compiler detected: breaking change PR contains a commit with a breaking change detected: feature PR contains a feature commit target: major This PR is targeted for the next major release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants