Angular quick start

In this quick start you'll learn how to start delivering your media from Cloudinary using Angular.

Tip
If you aren't familiar with Cloudinary, you may want to first take a look at the Developer get started guide for a high-level overview of integrating Cloudinary into your code, and an introduction to the main concepts.

You may also find our Glossary helpful to understand Cloudinary-specific terminology.

Two libraries are required:

Tip
To get a more in-depth understanding of the architecture, you may want to start from the Angular SDK introduction.

1. Install packages

Install the required packages using the NPM package manager:

Copy to clipboard
npm i @cloudinary/url-gen @cloudinary/ng

2. Add Cloudinary to your code

Note
This step assumes that you have assets already uploaded in your account. To upload files within your app, see Angular SDK image and video upload. Additionally, you can use the CLI to upload files programmatically, or log into your Media Library to upload files manually.

Copy to clipboard
// app.module.ts

// 1. Import classes
//===================

// Import the CloudinaryModule.
import {CloudinaryModule} from '@cloudinary/ng';

imports: [
  ...,
  CloudinaryModule
],
...
Copy to clipboard
// app.component.ts

import {Component, OnInit} from '@angular/core';

// Import the Cloudinary classes.
import {Cloudinary, CloudinaryImage} from '@cloudinary/url-gen';

// Import any actions required for transformations.
import {fill} from '@cloudinary/url-gen/actions/resize';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
})

export class AppComponent implements OnInit{
  img: CloudinaryImage;

  ngOnInit() {


    // 2. Set your cloud name
    //========================

    // Create a Cloudinary instance and set your cloud name.
    const cld = new Cloudinary({
      cloud: {
        cloudName: 'demo'
      }
    });


    // 3. Get your image
    //===================

    // Instantiate a CloudinaryImage object for the image with the public ID, 'docs/models'.
    this.img = cld.image('docs/models');


    // 4. Transform your image
    //=========================

    // Resize to 250 x 250 pixels using the 'fill' crop mode.
    this.img.resize(fill().width(250).height(250));

  }
}
Copy to clipboard
<!-- app.component.html -->

<!-- 5. Deliver your image
 ========================= -->

<!-- In your view, render the image in an Angular component.-->
<advanced-image [cldImg]="img"></advanced-image>

3. See the result!

Transformed models image

4. Try it yourself

Here's the full example:

This code is also available in GitHub.

Ready to learn more?

  • Understand the architecture of the Angular SDK and get a more detailed overview of the libraries.
  • Find out more about transforming images using @cloudinary/url-gen.
  • Learn about transforming videos using @cloudinary/url-gen.
  • Discover ways to improve load times and make your images responsive and accessible using plugins.

✔️ Feedback sent!

Rate this page: