
Research
Malicious npm Packages Impersonate Flashbots SDKs, Targeting Ethereum Wallet Credentials
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
ngx-responsive-image
Advanced tools
Load properly sized images in an Angular app using the Angular CDK BreakpointObserver to change image sources on breakpoint changes.
Load properly sized images in an Angular app using the Angular CDK BreakpointObserver to change image sources on breakpoint changes.
npm install --save ngx-responsive-image@latest @angular/cdk@latest
Import the NgxResponsiveImageModule and the Angular CDK ObserversModule to app.module.ts.
import { ObserversModule } from '@angular/cdk/observers';
import {
DEFAULT_BREAKPOINTS,
DEFAULT_WIDTHS,
NgxResponsiveImageModule
} from 'ngx-responsive-image';
@NgModule({
declarations: [AppComponent],
imports: [
ObserversModule,
NgxResponsiveImageModule.forRoot(DEFAULT_BREAKPOINTS, DEFAULT_WIDTHS)
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule {}
First if the image is on a component in a vhild module import NgxResponsiveImageModule into the module (without calling forRoot()).
Add the responsiveImage directive to the img
<img responsiveImage />
If you want a placeholder/default image, which is recommened if you are using Universal set the src atributes to the placeholder url.
<img responsiveImage src="assets/images/placeholder.jpg" />
Set the imgSrc attribute to the CDN url of the image replace the static width value with :width
<img
responsiveImage
src="assets/images/placeholder.jpg"
imgSrc="http://imageflare/image1/:width"
/>
If you a binding to a component property in that case remember to use [imgSrc]
You can set custom breakpoints when call NgxResponsiveImageModule.forRoot() be sure to supply the correpsonding image widths to be used in the same order as the breakpoints.
@NgModule({
declarations: [AppComponent],
imports: [
NgxResponsiveImageModule.forRoot(
[Breakpoints.HandsetPortrait, Breakpoints.HandsetLandscape],
[600, 960]
)
],
providers: [],
bootstrap: [AppComponent]
})
Set the manual attribute to true on the image(s) and use the breakpointUp event.
<img
imgSrc="http://localhost:4000/cdn/banner/:width"
src="assets/images/placeholder.jpg"
responsiveImage
[manual]="true"
alt="test manual image"
(breakpointUp)="updateImage($event, img)"
mat-card-image
#img
/>
updateImage(event: BreakpointChangeEvent, img: HTMLImageElement) {
this.renderer2.setAttribute(
img,
'src',
event.imgSrc.replace(':width', event.width.toString())
);
}
FAQs
Load properly sized images in an Angular app using the Angular CDK BreakpointObserver to change image sources on breakpoint changes.
We found that ngx-responsive-image demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
Security News
Ruby maintainers from Bundler and rbenv teams are building rv to bring Python uv's speed and unified tooling approach to Ruby development.
Security News
Following last week’s supply chain attack, Nx published findings on the GitHub Actions exploit and moved npm publishing to Trusted Publishers.