Comments (5)
Hi,
You're looking for conditional directives. Directive matching needs the selector to be static so this isn't at all supported and currently works as designed.
The alternative here is to handle the condition in the directive itself by passing an input.
from angular.
We discussed this issue just now and this is working as intended, with no plans to change the behavior.
Our reasoning is that an attr.
binding results in a conditional attribute, as the attribute is being removed if the binding evaluates to null
.
If you want to achieve this behavior, you can setup an attribute mirror from a bound property:
@Component({
host: {
'[attr.mirror]': 'mirror',
}
})
export class MyCmp {
@Input()
mirror: string;
}
which is then set using a property binding instead of an explicit attribute binding.
from angular.
But this will work only with components. What if i need to apply it on span 🤦.
from angular.
But this will work only with components. What if i need to apply it on span 🤦.
I don't follow. If you have e.g. <span [trimmed]="trimmed"></span>
and a directive:
@Directive({
selector: '[trimmed]',
host: { '[attr.trimmed]': 'trimmed' }
})
export class MyDir {
@Input() trimmed: boolean;
}
that should do the trick?
from angular.
i will check this thx. but still looks like shoot a fly with a cannon :)
from angular.
Related Issues (20)
- AngularJS structural directives doesn't render Angular web components created using Angular elements HOT 1
- i18n hydration fails when multiple elements are inside an i18n tag HOT 1
- Not able to redirect to Angular V17 Page HOT 2
- Support for Content-Security-Policy using HASH (sha-256)
- App using ngmodule does not get localeid set after upgrade to 18 HOT 2
- Link images tuto are dead HOT 1
- computed() re evaluation issue(?) HOT 2
- Add a way to receive old value when a signal changes HOT 1
- Add better way to get signal value without calling it like method HOT 1
- If our product used angular13,when vulnerabilities or importante bugs were found, will you fix them for patch on version 13.x? HOT 2
- Images used in the training are not available HOT 1
- Standalone from a global config HOT 1
- Pipes documentation missing at https://angular.dev/api/common#pipes HOT 1
- activatedRoute.getAllParams() which includes all params from children
- An Angular.io page seems to be down HOT 6
- ERR_INVALID_URL thrown during prerendering ngSrc with priority attribute
- Tutorial assets unavailable HOT 1
- Access to options object in ControlValueAccessor's writeValue method HOT 1
- Signal in Service not working HOT 2
- Wrong Link
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from angular.