<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Sudhakar George</title>
    <description>The latest articles on DEV Community by Sudhakar George (@sudhakar_george_e6d1f136f).</description>
    <link>https://dev.to/sudhakar_george_e6d1f136f</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F2156845%2F3fa03a47-9f8c-41d2-a448-096979d86338.jpg</url>
      <title>DEV Community: Sudhakar George</title>
      <link>https://dev.to/sudhakar_george_e6d1f136f</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/sudhakar_george_e6d1f136f"/>
    <language>en</language>
    <item>
      <title>Integrating sg-autocomplete Component</title>
      <dc:creator>Sudhakar George</dc:creator>
      <pubDate>Mon, 03 Mar 2025 22:39:49 +0000</pubDate>
      <link>https://dev.to/sudhakar_george_e6d1f136f/integrating-sg-autocomplete-component-3m58</link>
      <guid>https://dev.to/sudhakar_george_e6d1f136f/integrating-sg-autocomplete-component-3m58</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5jqzk71z3elgmqvwdqst.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5jqzk71z3elgmqvwdqst.png" alt="Image description" width="800" height="214"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What is the sg-autocomplete Component?
&lt;/h2&gt;

&lt;p&gt;The sg-autocomplete component is a user interface element that functions like a text input field. As the user types, it dynamically suggests relevant options from a predefined JSON list, allowing them to quickly select a matching value instead of typing the full term manually.&lt;/p&gt;

&lt;p&gt;You can configure it with any elements from the JSON file. &lt;/p&gt;

&lt;p&gt;You can navigate the autocomplete dropdown using the mouse or tab key from the keyboard.&lt;/p&gt;

&lt;h2&gt;
  
  
  Getting Started
&lt;/h2&gt;

&lt;p&gt;Use the below command to add your package in your application&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm i sg-autocomplete
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can consume it in your application as shown below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;sg-autocomplete autotext="JSON-ELEMENT-NAME"&amp;gt;&amp;lt;/sg-autocomplete&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Say, for &lt;em&gt;Example&lt;/em&gt;, if your JSON element is like this&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
    url: "https://cdn-icons-png.flaticon.com/512/1804/1804486.png", 
    title: "URL", 
    description:"URL"
  },
  {
    url: "https://i.ibb.co/7XqwsLw/fox.jpg",
    title: "Fox", 
    description:"Fox"
 },
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you want to add "description" to the autocomplete suggestion list, you can do so like this&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sg-autocomplete autotext="description"&amp;gt;&amp;lt;/sg-autocomplete&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Options
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbeoylhcf87zwi5slrszk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbeoylhcf87zwi5slrszk.png" alt="Image description" width="800" height="262"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Examples
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwm4xk4qzzsleq3vm274w.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwm4xk4qzzsleq3vm274w.png" alt="Image description" width="699" height="800"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Usage
&lt;/h2&gt;

&lt;p&gt;Now, we will see how to integrate this library into your applications.&lt;/p&gt;

&lt;h2&gt;
  
  
  a) Vanilla JavaScript
&lt;/h2&gt;

&lt;p&gt;You can include the component in your HTML file in two ways:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Using a CDN:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Add a &lt;strong&gt;&lt;/strong&gt; tag in your HTML file's &lt;strong&gt;&lt;/strong&gt;, pointing to the component's JavaScript file hosted on a CDN. &lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;script src="https://cdn.jsdelivr.net/npm/sg-autocomplete/dist/sg-autocomplete/sg-autocomplete.js"&amp;gt;&amp;lt;/script&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;2) &lt;strong&gt;Using ES Modules:&lt;/strong&gt; &lt;br&gt;
If you prefer to use ES Modules, you can import the component using an import statement:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; &amp;lt;script type="module"&amp;gt;
   import { defineCustomElements } from './dist/sg- 
   autocomplete/loader/index.es2017.mjs';
   defineCustomElements();
 &amp;lt;/script&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Make sure to adjust the paths according to your project structure.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Use the component in your HTML:&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;You can now use the component in your HTML like any other HTML element:&lt;br&gt;
Code&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; &amp;lt;sg-autocomplete autotext="description" dropdown=true &amp;gt;
&amp;lt;/sg-autocomplete&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Interact with the component using JavaScript:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Example of setting the JSON data:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; const autocompleteLst = [
        {url: "https://cdn-icons-png.flaticon.com/512/1804/1804486.png", title: "URL", description:"URL"},
        {url: "https://i.ibb.co/dBCHzXQ/paris.jpg", title: "Paris Eiffel", description:"Paris Eiffel"},
        {url: "https://i.ibb.co/JKB0KPk/pizza.jpg", title: "Pizza Time", description:"Pizza Time"},
        {url: "https://i.ibb.co/VYYPZGk/salmon.jpg", title: "Salmon ", description:"Salmon"},
      ];
      document.querySelector('sg-autocomplete').suggestionlist = autocompleteLst
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can access and manipulate the component using standard DOM APIs:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; const input = document.querySelector('#sg-autocomplete');
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Handling Events:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  input.addEventListener('click', function(event) {
  // Code to execute when the button is clicked
     console.log('Input Value:'+ event.target.value);
 });

  input.addEventListener("keydown", (e) =&amp;gt; {
     console.log(e.key+'Input Value keydown:'+ e.target.value);
  }); 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  b) Angular
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Step 1:&lt;/em&gt;&lt;/strong&gt;  Add an import to &lt;code&gt;main.ts&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { defineCustomElements} from '../node_modules/sg-autocomplete/loader';
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And somewhere near the bottom, we'll call this function.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;defineCustomElements();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;&lt;em&gt;Step 2:&lt;/em&gt;&lt;/strong&gt; Next, in &lt;code&gt;app.module.ts&lt;/code&gt; add the &lt;code&gt;CUSTOM_ELEMENTS_SCHEMA&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import {CUSTOM_ELEMENTS_SCHEMA} from `@angular/core`;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and then&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;schemas: [
    CUSTOM_ELEMENTS_SCHEMA
]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Your &lt;code&gt;app.module.ts&lt;/code&gt; should look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { NgModule, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';

@NgModule({
  declarations: [],
  imports: [],
  schemas: [ CUSTOM_ELEMENTS_SCHEMA],
  providers: [],
  bootstrap: [AppComponent]
})

export class AppModule { }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Please Note: schemas [ CUSTOM_ELEMENTS_SCHEMA ] need to be added to each component where you are using custom HTML tags.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Step 3:&lt;/em&gt;&lt;/strong&gt; Declare the arrayData: In your Angular component's TypeScript file, declare the arrayData that you are passing.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; arrayData  =[{"url": "https://i.ibb.co/10fFGkZ/car-race.jpg", "title": "Car Racing", "description":"Car Racing"} , 
    {"url": "https://i.ibb.co/gM5NNJX/butterfly.jpg", "title": "Butterfly", "description":"Butterfly"},
    {"url": "https://i.ibb.co/ygqHsHV/coffee-milk.jpg", "title": "Coffee with Milk", "description":"Coffee with Milk"}];
  autotext  =this.arrayData ;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, Set the array data value to the sg-autocomplete component&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; ngOnInit() {
     const myElement = this.el.nativeElement.querySelector('sg-autocomplete');
      if (myElement) {
        myElement.suggestionlist =this.autotext;
      }
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;&lt;em&gt;Step 4:&lt;/em&gt;&lt;/strong&gt; Now, in &lt;code&gt;app.component.html&lt;/code&gt; you utilize your new custom element.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   &amp;lt;sg-autocomplete autotext="description" dropdown=true&amp;gt;&amp;lt;/sg-autocomplete&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note: Here, "description" is the JSON element name that will show it as a drop-down suggestion list.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Step 5:&lt;/em&gt;&lt;/strong&gt; To consume the autocomplete value, you can create a function to access it like this&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; getValue() {
      const autocompleteValue = this.el.nativeElement.querySelector('sg-autocomplete') as HTMLInputElement;
    } 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  c) React
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;Step 1:&lt;/em&gt;&lt;br&gt;
Now we'll add an import to &lt;code&gt;index.js&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { defineCustomElements} from '../node_modules/sg-autocomplete/loader';
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And somewhere near the bottom, we'll call this function.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;defineCustomElements();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 2:&lt;/strong&gt;&lt;br&gt;
Next, in &lt;code&gt;app.js&lt;/code&gt; Pass the json array and utilize the new custom element,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function App() {
  const arrayData  =[{"url": 
    {"url": "https://i.ibb.co/gM5NNJX/butterfly.jpg", "title": "Butterfly", "description":"Butterfly"},
    {"url": "https://i.ibb.co/ygqHsHV/coffee-milk.jpg", "title": "Coffee with Milk", "description":"Coffee with Milk"},
    {"url": "https://i.ibb.co/7XqwsLw/fox.jpg", "title": "Fox", "description":"Fox"},
    ];

  const myElement = useRef(arrayData);
    useEffect(() =&amp;gt; {
      if (myElement.current) {
        const element = myElement.current;
        document.querySelector('sg-autocomplete').suggestionlist = element;
      }
    }, []);
  return (
    &amp;lt;div&amp;gt;
          &amp;lt;sg-autocomplete autotext="description" dropdown="true"&amp;gt;&amp;lt;/sg-autocomplete&amp;gt;
    &amp;lt;/div&amp;gt;
  );
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  d) Vue
&lt;/h2&gt;

&lt;p&gt;Add defineCustomElements to one of our main files. Specifically &lt;code&gt;main.js&lt;/code&gt; for Vue.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { defineCustomElements} from '../node_modules/sg-autocompleter/loader';
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And somewhere near the bottom, we'll call this function.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;defineCustomElements();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next, in &lt;code&gt;App.Vue&lt;/code&gt;, you consume the custom element.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;template&amp;gt;
  &amp;lt;div&amp;gt;
  &amp;lt;sg-autocomplete autotext="description" dropdown="true"&amp;gt;&amp;lt;/sg-autocomplete&amp;gt;
  &amp;lt;/div&amp;gt;
&amp;lt;/template&amp;gt;

&amp;lt;script&amp;gt;
    export default {
      data() {
        return {
        arrayData:[
            {"url": "https://i.ibb.co/gM5NNJX/butterfly.jpg", "title": "Butterfly", "description":"Butterfly"},
            {"url": "https://i.ibb.co/VYYPZGk/salmon.jpg", "title": "Salmon ", "description":"Salmon"},
            {"url": "https://i.ibb.co/10fFGkZ/car-race.jpg", "title": "Car Racing", "description":"Car Racing"}  
           ]
      }
   },
    mounted() {
      document.querySelector('sg-autocomplete').suggestionlist = this.arrayData;
    }
};
&amp;lt;/script&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt;&lt;a href="https://codesandbox.io/p/devbox/pj6n2w" rel="noopener noreferrer"&gt;Click Here&lt;/a&gt; for Vue application live demo.&lt;/p&gt;




&lt;p&gt;Hope this article is useful to you and your project. If you like this article, like &amp;amp; share it with your friends.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/sudhakar_george_e6d1f136f"&gt;Follow Me&lt;/a&gt; for more articles.&lt;/p&gt;

</description>
      <category>angular</category>
      <category>vue</category>
      <category>react</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Integrating sg-image-viewer component in Angular, Vue and React Application</title>
      <dc:creator>Sudhakar George</dc:creator>
      <pubDate>Fri, 24 Jan 2025 02:43:47 +0000</pubDate>
      <link>https://dev.to/sudhakar_george_e6d1f136f/integrating-sg-image-viewer-component-in-angular-vue-and-react-application-23o</link>
      <guid>https://dev.to/sudhakar_george_e6d1f136f/integrating-sg-image-viewer-component-in-angular-vue-and-react-application-23o</guid>
      <description>&lt;div class="ltag__link"&gt;
  &lt;a href="/sudhakar_george_e6d1f136f" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&gt;
      &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F2156845%2F3fa03a47-9f8c-41d2-a448-096979d86338.jpg" alt="sudhakar_george_e6d1f136f"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="https://dev.to/sudhakar_george_e6d1f136f/integrating-sg-image-viewer-component-27a1" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;Integrating sg-image-viewer component&lt;/h2&gt;
      &lt;h3&gt;Sudhakar George ・ Jan 24&lt;/h3&gt;
      &lt;div class="ltag__link__taglist"&gt;
        &lt;span class="ltag__link__tag"&gt;#angular&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#react&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#vue&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#webcomponents&lt;/span&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;


</description>
      <category>angular</category>
      <category>vue</category>
      <category>react</category>
      <category>frontend</category>
    </item>
    <item>
      <title>Integrating sg-image-viewer component</title>
      <dc:creator>Sudhakar George</dc:creator>
      <pubDate>Fri, 24 Jan 2025 02:30:56 +0000</pubDate>
      <link>https://dev.to/sudhakar_george_e6d1f136f/integrating-sg-image-viewer-component-27a1</link>
      <guid>https://dev.to/sudhakar_george_e6d1f136f/integrating-sg-image-viewer-component-27a1</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fw4f6tqmh6wv16mcefj0s.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fw4f6tqmh6wv16mcefj0s.png" alt="Image description" width="800" height="215"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What is sg-image-viewer?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;An "image viewer component" is used to view multiple images in a gallery-like format, allowing users to easily switch between related pictures.&lt;br&gt;
The image viewer component seamlessly integrates with the rest of the application, it directly access the data from the application's in JSON format.&lt;br&gt;
Overall, the tight integration of the image viewer component with the application's core infrastructure ensures a fast, reliable, and scalable solution for image rendering and management.&lt;/p&gt;

&lt;p&gt;In this article we will go over how to integrating sg-image-viewer component with Angular, React and Vue Applications in detail.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Getting Started&lt;/strong&gt;&lt;br&gt;
Use the below command to add your package in your application&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm i sg-image-viewer
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can consume it in your application as shown below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;sg-image-viewer imageList='IMAGE_JSON_DATA_LIST' &amp;gt;&amp;lt;/sg-image-viewer&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Please note your can provide your list of images as the imageList value which returns as JSON Array. Your JSON Array looks something like this. It has 3 properties &lt;strong&gt;url, title&lt;/strong&gt; and &lt;strong&gt;description&lt;/strong&gt;.&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[
 {
   "url": "https://i.ibb.co/gM5NNJX/butterfly.jpg",
    "title": "Butterfly",
    "description":"Butterfly"
  },
  {
   "url": "https://i.ibb.co/ygqHsHV/coffee-milk.jpg",
   "title": "Coffee with Milk", 
    "description":"Coffee with Milk"
   },
];
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Options :&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Please find the complete options avaliable for the user to configure it based on their needs.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fc08osu1w091j9a0tvxb6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fc08osu1w091j9a0tvxb6.png" alt="Image description" width="800" height="563"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Pagniation will be added at the bottom as default. Default page size is 10 per page&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Examples:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgfjo8qz1ldvc32v7n4t3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgfjo8qz1ldvc32v7n4t3.png" alt="Image description" width="710" height="743"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;1. Integrating with Angular Application&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1: Adding the component&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Go to your root folder of your angular application and use the below command to add the package.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm i sg-image-viewer&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Your package.json will be updated with the component as shown below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fz2jludgxk38b6sn81pr1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fz2jludgxk38b6sn81pr1.png" alt="Image description" width="512" height="346"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 2: Adding the Custom Elements in main.js&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Add an import to &lt;code&gt;main.ts&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { defineCustomElements} from '../node_modules/sg-image-viewer/loader';
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And somewhere near the bottom we’ll call this function.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;defineCustomElements();&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;your &lt;strong&gt;main.js&lt;/strong&gt; file looks like this&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';

import { AppModule } from './app/app.module';
import { defineCustomElements} from '../node_modules/sg-image-viewer/loader';

platformBrowserDynamic().bootstrapModule(AppModule, {
  ngZoneEventCoalescing: true
})
  .catch(err =&amp;gt; console.error(err));
  defineCustomElements();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 3: Adding the Custom Elements Schema in your module&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Next, in &lt;code&gt;app.module.ts&lt;/code&gt; add the &lt;code&gt;CUSTOM_ELEMENTS_SCHEMA&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import {CUSTOM_ELEMENTS_SCHEMA} from `@angular/core`;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and then&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;schemas: [
    CUSTOM_ELEMENTS_SCHEMA
]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Your &lt;code&gt;app.module.ts&lt;/code&gt; should look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { NgModule, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';

import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    AppRoutingModule,
  ],
  schemas:[CUSTOM_ELEMENTS_SCHEMA],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Please Note:&lt;/strong&gt; schemas: [ CUSTOM_ELEMENTS_SCHEMA ] need to be added to each component where you are using custom HTML tags.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Step 4: Declare the imageList data&lt;/strong&gt;&lt;br&gt;
In your Angular component's TypeScript file, declare the arrayData that you are passing. I am adding it in &lt;code&gt;app.component.ts &lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { Component } from '@angular/core';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrl: './app.component.css'
})
export class AppComponent {
  title = 'angular-webcomponent';
  arrayData  =[{"url": "https://static.pexels.com/photos/52500/horse-herd-fog-nature-52500.jpeg","title": "Horse", "description": "Horse"}, 
    {"url": "https://i.ibb.co/gM5NNJX/butterfly.jpg", "title": "Butterfly", "description":"Butterfly"},
    {"url": "https://i.ibb.co/ygqHsHV/coffee-milk.jpg", "title": "Coffee with Milk", "description":"Coffee with Milk"},
    {"url": "https://i.ibb.co/7XqwsLw/fox.jpg", "title": "Fox", "description":"Fox"},
    {"url": "https://i.ibb.co/L1m1NxP/girl.jpg", "title": "Mountain Girl", "description":"Mountain Girl"},
    {"url": "https://images.pexels.com/photos/1559117/pexels-photo-1559117.jpeg?auto=compress&amp;amp;cs=tinysrgb&amp;amp;dpr=2&amp;amp;h=750&amp;amp;w=1260", "title": "Winter", "description":"Winter"},
    {"url": "https://static.pexels.com/photos/213399/pexels-photo-213399.jpeg", "title": "Koi Fish", "description":"Koi Fish"},
    {"url": "https://i.ibb.co/dBCHzXQ/paris.jpg", "title": "Paris Eiffel", "description":"Paris Eiffel"},
    {"url": "https://i.ibb.co/JKB0KPk/pizza.jpg", "title": "Pizza Time", "description":"Pizza Time"},
    {"url": "https://i.ibb.co/VYYPZGk/salmon.jpg", "title": "Salmon ", "description":"Salmon"},
    {"url": "https://i.ibb.co/10fFGkZ/car-race.jpg", "title": "Car Racing", "description":"Car Racing"}  
    ];

  imageList  =this.arrayData ;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 5: Consume it in your Html file.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Now, in &lt;code&gt;app.component.html&lt;/code&gt; add the sg-image-viewer component.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;sg-image-viewer  [imageList]="arrayData" mode="carousel"  gallery-style="frame"&amp;gt;&amp;lt;/sg-image-viewer&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;your output will be like this&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fidrakhckrlekwbwj6ygv.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fidrakhckrlekwbwj6ygv.gif" alt="Image description" width="800" height="614"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;2. Integrating with React Application&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1: Adding the component&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Go to your root folder of your angular application and use the below command to add the package.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm i sg-image-viewer&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 2: Now we'll add an import to _index.js&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { defineCustomElements} from '../node_modules/sg-image-viewer/loader';
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And somewhere near the bottom we'll call this function.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;defineCustomElements();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 3: Next, in app.js Pass the json array and utilize the new custom element,&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function App() {
  const arrayData  =[{"url": 
    {"url": "https://i.ibb.co/gM5NNJX/butterfly.jpg", "title": "Butterfly", "description":"Butterfly"},
    {"url": "https://i.ibb.co/ygqHsHV/coffee-milk.jpg", "title": "Coffee with Milk", "description":"Coffee with Milk"},
    {"url": "https://i.ibb.co/7XqwsLw/fox.jpg", "title": "Fox", "description":"Fox"},
    ];
  return (
    &amp;lt;div className="App"&amp;gt;
       &amp;lt;sg-image-viewer imageList={arrayData}&amp;gt;&amp;lt;/sg-image-viewer&amp;gt;
    &amp;lt;/div&amp;gt;
  );
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;your output will be like this&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fl0n17a1sz1p877yqspp1.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fl0n17a1sz1p877yqspp1.gif" alt="Image description" width="400" height="185"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;3. Integrating with Vue Application&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1: Adding the component&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Go to your root folder of your angular application and use the below command to add the package.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm i sg-image-viewer&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 2: Add defineCustomElements to one of our main files. Specifically main.js for Vue.&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { defineCustomElements} from '../node_modules/sg-image-viewer/loader';
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And somewhere near the bottom we'll call this function.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;defineCustomElements();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 3: Next, in App.Vue you consume the custom element.&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;template&amp;gt;
  &amp;lt;div&amp;gt;
   &amp;lt;sg-image-viewer :image-list="JSON.stringify(arrayData)" 
      gallery-style="flexbox" header="true" header-title="sg-image- 
      viewer" isvue&amp;gt;&amp;lt;/sg-image-viewer&amp;gt; 
  &amp;lt;/div&amp;gt;
&amp;lt;/template&amp;gt;

&amp;lt;script&amp;gt;
export default {
  data() {
    return {
  arrayData:[{"url": "https://static.pexels.com/photos/52500/horse-herd-fog-nature-52500.jpeg","title": "Horse", "description": "Horse"}, 
    {"url": "https://i.ibb.co/gM5NNJX/butterfly.jpg", "title": "Butterfly", "description":"Butterfly"},
    {"url": "https://i.ibb.co/ygqHsHV/coffee-milk.jpg", "title": "Coffee with Milk", "description":"Coffee with Milk"},
    {"url": "https://i.ibb.co/7XqwsLw/fox.jpg", "title": "Fox", "description":"Fox"},
    {"url": "https://i.ibb.co/L1m1NxP/girl.jpg", "title": "Mountain Girl", "description":"Mountain Girl"},
    {"url": "https://images.pexels.com/photos/1559117/pexels-photo-1559117.jpeg?auto=compress&amp;amp;cs=tinysrgb&amp;amp;dpr=2&amp;amp;h=750&amp;amp;w=1260", "title": "Winter", "description":"Winter"},
    {"url": "https://static.pexels.com/photos/213399/pexels-photo-213399.jpeg", "title": "Koi Fish", "description":"Koi Fish"},
    {"url": "https://i.ibb.co/dBCHzXQ/paris.jpg", "title": "Paris Eiffel", "description":"Paris Eiffel"},
    {"url": "https://i.ibb.co/JKB0KPk/pizza.jpg", "title": "Pizza Time", "description":"Pizza Time"},
    {"url": "https://i.ibb.co/VYYPZGk/salmon.jpg", "title": "Salmon ", "description":"Salmon"},
    {"url": "https://i.ibb.co/10fFGkZ/car-race.jpg", "title": "Car Racing", "description":"Car Racing"}  
    ]
  }
};
&amp;lt;/script&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;your output will be like this&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9vu0mqdw40a74gl4ysvu.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9vu0mqdw40a74gl4ysvu.gif" alt="Image description" width="400" height="179"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;&lt;a href="https://codesandbox.io/p/devbox/sg-image-viewer-k9zn47" rel="noopener noreferrer"&gt;Click Here&lt;/a&gt; for Vue application live demo.&lt;/p&gt;




&lt;p&gt;Hope this article is useful to you and your project, If you like this article, like &amp;amp; share it with your friends.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/sudhakar_george_e6d1f136f"&gt;Follow Me&lt;/a&gt; for more articles.&lt;/p&gt;

</description>
      <category>angular</category>
      <category>react</category>
      <category>vue</category>
      <category>webcomponents</category>
    </item>
    <item>
      <title>tooltip component</title>
      <dc:creator>Sudhakar George</dc:creator>
      <pubDate>Tue, 17 Dec 2024 15:57:11 +0000</pubDate>
      <link>https://dev.to/sudhakar_george_e6d1f136f/tooltip-component-13g6</link>
      <guid>https://dev.to/sudhakar_george_e6d1f136f/tooltip-component-13g6</guid>
      <description>&lt;div class="ltag__link"&gt;
  &lt;a href="/sudhakar_george_e6d1f136f" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&gt;
      &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F2156845%2F3fa03a47-9f8c-41d2-a448-096979d86338.jpg" alt="sudhakar_george_e6d1f136f"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="https://dev.to/sudhakar_george_e6d1f136f/integrating-sg-tooltip-in-angular-project-35i" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;Integrating sg-tooltip in Angular Project&lt;/h2&gt;
      &lt;h3&gt;Sudhakar George ・ Dec 17 '24&lt;/h3&gt;
      &lt;div class="ltag__link__taglist"&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;


</description>
      <category>angular</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Integrating sg-tooltip in Angular Project</title>
      <dc:creator>Sudhakar George</dc:creator>
      <pubDate>Tue, 17 Dec 2024 15:34:46 +0000</pubDate>
      <link>https://dev.to/sudhakar_george_e6d1f136f/integrating-sg-tooltip-in-angular-project-35i</link>
      <guid>https://dev.to/sudhakar_george_e6d1f136f/integrating-sg-tooltip-in-angular-project-35i</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7vopjr858102nvcxdwm0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7vopjr858102nvcxdwm0.png" alt="Image description" width="800" height="260"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What is an Tooltip Component?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A tooltip component is a user interface (UI) element that displays extra information when a user interacts with a specific object, such as a button, icon, or text link. Tooltips are useful for providing more clarity to the user and can be used to describe the function of an element.&lt;/p&gt;

&lt;p&gt;Here are the sg-tooltip Component &lt;strong&gt;options&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwqncii679u5x8u2e8u1o.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwqncii679u5x8u2e8u1o.png" alt="Image description" width="672" height="765"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Animation Options:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fda3gc5uctadyxh84djie.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fda3gc5uctadyxh84djie.gif" alt="Image description" width="800" height="134"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;sg-tooltip component integration in Angular Application&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Step 1: Adding the component&lt;/strong&gt;&lt;br&gt;
Go to your root folder of your angular application and use the below command to add the package.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; npm i sg-tooltip
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Your &lt;strong&gt;&lt;em&gt;package.json&lt;/em&gt;&lt;/strong&gt; will be updated with the component as shown below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fto5183almftmvkli6oas.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fto5183almftmvkli6oas.png" alt="Image description" width="561" height="403"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step2: Configure the main.js file&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Add an import to &lt;strong&gt;main.js&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And somewhere near the bottom, we’ll call this function.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;defineCustomElements();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;your &lt;strong&gt;main.js&lt;/strong&gt; file looks like this&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppModule } from './app/app.module';

import { defineCustomElements} from '../node_modules/sg-tooltip/loader';

platformBrowserDynamic().bootstrapModule(AppModule, {
  ngZoneEventCoalescing: true
})
  .catch(err =&amp;gt; console.error(err));
  defineCustomElements(); 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step3: Update the app.module.ts file&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Next, in &lt;strong&gt;app.module.ts&lt;/strong&gt; add the &lt;strong&gt;CUSTOM_ELEMENTS_SCHEMA&lt;/strong&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import {CUSTOM_ELEMENTS_SCHEMA} from `@angular/core`;
and then

schemas: [
    CUSTOM_ELEMENTS_SCHEMA
]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Your &lt;strong&gt;app.module.ts&lt;/strong&gt; should look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { NgModule, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';

@NgModule({
  declarations: [],
  imports: [],
  schemas: [ CUSTOM_ELEMENTS_SCHEMA],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Please Note: schemas: [ CUSTOM_ELEMENTS_SCHEMA ] need to be added to each component where you are using custom HTML tags.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Step 4: Consume it in your Html file.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Now, in app.component.html add the sg-tooltip component.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;sg-tooltip tooltip-text="Hover the Text" tooltip-title="Basic Tooltip"&amp;gt;&amp;lt;/sg-tooltip&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://codesandbox.io/p/devbox/sg-tooltip-component-k5ss3m?embed=1" rel="noopener noreferrer"&gt;Click Here&lt;/a&gt; for live Demo.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This &lt;strong&gt;sg-tooltip&lt;/strong&gt; component have different options, you can configure it based on your project needs.&lt;/p&gt;

&lt;p&gt;Hope this article is useful to you and your project, If you like this article, &lt;a href="https://dev.to/sudhakar_george_e6d1f136f/integrating-sg-tooltip-in-angular-project-35i"&gt;like &amp;amp; share&lt;/a&gt; it with your friends.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/sudhakar_george_e6d1f136f"&gt;Follow Me&lt;/a&gt; for more articles.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Integrating sg-json-table component with Angular Application</title>
      <dc:creator>Sudhakar George</dc:creator>
      <pubDate>Thu, 21 Nov 2024 16:10:34 +0000</pubDate>
      <link>https://dev.to/sudhakar_george_e6d1f136f/integrating-sg-json-table-component-with-angular-application-40g8</link>
      <guid>https://dev.to/sudhakar_george_e6d1f136f/integrating-sg-json-table-component-with-angular-application-40g8</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F81dzd40cirtn5gna9qtg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F81dzd40cirtn5gna9qtg.png" alt="Image description" width="800" height="243"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What is sg-json-table Component ?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This component is used to load the data from the API returning JSON Array. &lt;/p&gt;

&lt;p&gt;You just need to provide the data-url which returns JSON Array, It will load and display table with pagination, search, print options. You can also customize the options and themes based on your needs.&lt;/p&gt;

&lt;p&gt;I created an sg-json-table component, devloper just need to use the tag and configure it based on their needs.&lt;/p&gt;

&lt;p&gt;In this article we will go over how to integrating sg-json-table component with Angular Application in detail.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Getting Started&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Use the below command to add your package in your application&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm i sg-json-table
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;you can consume it in your application as shown below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;sg-table data-url='YOUR_API_URL' &amp;gt;&amp;lt;/sg-table&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Please note your can provide your API URL as the data-url value which returns as JSON Array. Your JSON array looks like this&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[
  {
    "name": "Adeel Solangi",
     "id": "V59OF92YF627HFY0",
  },
  {
    "name": "Afzal Ghaffar",
     "id": "ENTOCR13RSCLZ6KU",
  }]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Options :&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You can find the complete options avaliable for the user to configure it based on their needs.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwl36szulane28vvtjuyx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwl36szulane28vvtjuyx.png" alt="Image description" width="800" height="681"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Examples :&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0gnq2ov36z0iljwn7p3j.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0gnq2ov36z0iljwn7p3j.png" alt="Image description" width="800" height="711"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Step 1: Adding the component&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
Go to your root folder of your angular application and use the below command to add the package.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm i sg-json-table
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Your &lt;strong&gt;package.json&lt;/strong&gt; will be updated with the component as shown below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fn23sascxa11e3es2w6u2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fn23sascxa11e3es2w6u2.png" alt="Image description" width="486" height="437"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 2: Adding the Custom Elements in main&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Add an import to &lt;strong&gt;main.ts&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { defineCustomElements} from '../node_modules/sg-json-table/loader';
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And somewhere near the bottom we'll call this function.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;defineCustomElements();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Please Note: If you are using multiple component then you can define the defineCustomElements as shown below:&lt;/p&gt;


&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { defineCustomElements as defineCustomElements1} from '../node_modules/sg-copyright/loader';
import { defineCustomElements as defineCustomElements2} from '../node_modules/sg-avatar/loader';
import { defineCustomElements as defineCustomElements3} from '../node_modules/sg-table/loader';
.
.
.
defineCustomElements1();
defineCustomElements2();
defineCustomElements3();
&lt;/code&gt;&lt;/pre&gt;

&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Step 3: Adding the Custom Elements Schema in your module&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Next, in &lt;strong&gt;app.module.ts&lt;/strong&gt; add the CUSTOM_ELEMENTS_SCHEMA.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import {CUSTOM_ELEMENTS_SCHEMA} from `@angular/core`;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and then&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;schemas: [
    CUSTOM_ELEMENTS_SCHEMA
]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Your &lt;strong&gt;app.module.ts&lt;/strong&gt; should look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { NgModule, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
@NgModule({
  declarations: [],
  imports: [],
  schemas: [ CUSTOM_ELEMENTS_SCHEMA],
  providers: [],
  bootstrap: [AppComponent]
})export class AppModule { }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Please Note: schemas: [ CUSTOM_ELEMENTS_SCHEMA ] need to be added to each component where you are using custom HTML tags.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Step 4: Consume it in your Html file.&lt;/strong&gt;&lt;br&gt;
Now, in app.component.html add the sg-avatar component.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;sg-table data-url='https://microsoftedge.github.io/Demos/json-dummy-data/128KB.json'info='true' paging="true"&amp;gt;
&amp;lt;/sg-table&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://codesandbox.io/p/devbox/green-leftpad-9f795x?embed=1&amp;amp;file=%2Fsrc%2Fapp%2Fapp.component.html%3A23%2C1&amp;amp;showConsole=true" rel="noopener noreferrer"&gt;Click Here&lt;/a&gt; for live example&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion:&lt;/strong&gt;&lt;br&gt;
This &lt;strong&gt;sg-json-table&lt;/strong&gt; component have different options, you can configure it based on your project needs.&lt;/p&gt;

&lt;p&gt;Hope this article is useful to you and your project, If you like this article, &lt;a href="https://dev.to/sudhakar_george_e6d1f136f/integrating-sg-json-table-component-with-angular-application-40g8"&gt;like &amp;amp; share&lt;/a&gt; it with your friends.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/sudhakar_george_e6d1f136f"&gt;Follow Me&lt;/a&gt; for more articles.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Integrating sg-avatar Component in Angular Application</title>
      <dc:creator>Sudhakar George</dc:creator>
      <pubDate>Thu, 14 Nov 2024 15:00:41 +0000</pubDate>
      <link>https://dev.to/sudhakar_george_e6d1f136f/integrating-sg-avatar-component-in-angular-application-2hf7</link>
      <guid>https://dev.to/sudhakar_george_e6d1f136f/integrating-sg-avatar-component-in-angular-application-2hf7</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fec6ox0luuspuf4cd480y.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fec6ox0luuspuf4cd480y.png" alt="Image description" width="785" height="356"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What is an Avatar Component?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;An avatar component is a user interface (UI) element that displays visual or textual content to represent a user’s identity. Avatars can be used to display information about a user in various places, such as menus, tables, and chats.&lt;/p&gt;

&lt;p&gt;I created an avatar component, devloper just need to use the tag and configure it based on their needs.&lt;/p&gt;

&lt;p&gt;In this article we will go over how to integrating sg-avatar component with Angular Application in detail.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;sg-avatar component integration in Angular Application&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Step 1: Adding the component&lt;/em&gt;&lt;br&gt;
Go to your root folder of your angular application and use the below command to add the package.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm i sg-avatar&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Your package.json will be updated with the component as shown below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fg27bq8l3xdrc7yumndqo.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fg27bq8l3xdrc7yumndqo.png" alt="Image description" width="522" height="423"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Step2: Configure the angular.json file&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Now you need to configure the angular.json file. You’ll add this configuration under the &lt;strong&gt;projects &amp;gt; yourProjectName &amp;gt; architect &amp;gt; build &amp;gt; options &amp;gt; assets&lt;/strong&gt; section:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"input": "node_modules/sg-avatar/dist/components/assets/",
"output": "/assets/"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Your &lt;strong&gt;angular.json&lt;/strong&gt; should look like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6vqassrx60pozl1jozsx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6vqassrx60pozl1jozsx.png" alt="Image description" width="791" height="672"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Please note that this will copy the images from the avatar component and place it in your application build folder. If you are not going to use male and female images then you can skip this step.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fogj98tc8qzncvvb6q18p.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fogj98tc8qzncvvb6q18p.png" alt="Image description" width="222" height="262"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjzzqsuj5crp1114mkrgz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjzzqsuj5crp1114mkrgz.png" alt="Image description" width="800" height="122"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Step 3: Adding the Custom Elements in main&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Add an import to &lt;strong&gt;main.ts&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;import { defineCustomElements} from '../node_modules/sg-avatar/loader';&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;And somewhere near the bottom we’ll call this function.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;defineCustomElements();&lt;/code&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Please Note: If you are using multiple component then you can define the defineCustomElements as shown below:&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { defineCustomElements as defineCustomElements1} from '../node_modules/sg-copyright/loader';
import { defineCustomElements as defineCustomElements2} from '../node_modules/sg-avatar/loader';
.
.
.
defineCustomElements1();
defineCustomElements2();

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;&lt;em&gt;Step 4: Adding the Custom Elements Schema in your module&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Next, in &lt;strong&gt;app.module.ts&lt;/strong&gt; add the &lt;strong&gt;CUSTOM_ELEMENTS_SCHEMA&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;import {CUSTOM_ELEMENTS_SCHEMA} from&lt;/code&gt;@angular/core&lt;code&gt;;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;and then&lt;/p&gt;

&lt;p&gt;&lt;code&gt;schemas: [&lt;br&gt;
    CUSTOM_ELEMENTS_SCHEMA&lt;br&gt;
]&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Your &lt;strong&gt;app.module.ts&lt;/strong&gt; should look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { NgModule, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
@NgModule({
  declarations: [],
  imports: [],
  schemas: [ CUSTOM_ELEMENTS_SCHEMA],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Please Note: schemas: [ &lt;strong&gt;_CUSTOM_ELEMENTS_SCHEMA _&lt;/strong&gt;] need to be added to each component where you are using custom HTML tags.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Step 5: Consume it in your Html file.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Now, in app.component.html add the sg-avatar component.&lt;/p&gt;

&lt;blockquote&gt;

&lt;/blockquote&gt;

&lt;p&gt;Conclusion:&lt;/p&gt;

&lt;p&gt;This sg-avatar component have different options, you can configure it based on your needs.&lt;/p&gt;

&lt;p&gt;Options&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fumk2szi0w4pi5fgj6dom.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fumk2szi0w4pi5fgj6dom.png" alt="Image description" width="800" height="650"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Example:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4beo2sac96guy9rmxl6g.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4beo2sac96guy9rmxl6g.png" alt="Image description" width="800" height="356"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Hope this article is useful to you and your project, If you like this article, &lt;a href="https://dev.to/sudhakar_george_e6d1f136f/integrating-sg-avatar-component-in-angular-application-2hf7"&gt;like &amp;amp; share&lt;/a&gt; it with your friends.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/sudhakar_george_e6d1f136f"&gt;Follow Me&lt;/a&gt; for more articles.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Integrating Stencil Web Components in Angular Project</title>
      <dc:creator>Sudhakar George</dc:creator>
      <pubDate>Tue, 05 Nov 2024 02:57:34 +0000</pubDate>
      <link>https://dev.to/sudhakar_george_e6d1f136f/integrating-stencil-web-components-in-angular-project-f9b</link>
      <guid>https://dev.to/sudhakar_george_e6d1f136f/integrating-stencil-web-components-in-angular-project-f9b</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcnto4ktg6eztx6nrjbki.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcnto4ktg6eztx6nrjbki.png" alt="Image description" width="800" height="279"&gt;&lt;/a&gt;&lt;br&gt;
Web Components is a suite of different technologies allowing you to create reusable custom user interface components.&lt;/p&gt;

&lt;p&gt;In this article, we’ll explore how to create custom Web Components using Stencil.js and integrate them into Angular applications.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What is Stencil.js?&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://stenciljs.com/" rel="noopener noreferrer"&gt;Stencil &lt;/a&gt;is an open-source compiler that generates standards-compliant web components. It builds highly performant, reusable components that can be used with any JavaScript framework or library. Created by the Ionic team, Stencil combines the best features of popular frameworks like Angular, React, and Vue, providing a simple and efficient way to build custom elements.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Advantages of Stencil Components&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Stencil provides some syntactic sugar with TSX (JSX with TypeScript), which makes it much easier to build web components with cleaner, reduced code.&lt;/li&gt;
&lt;li&gt;Stencil’s compiler performs static analysis on each component to customize the build. This results in a highly optimized runtime with minimal size&lt;/li&gt;
&lt;li&gt;Stencil will automatically polyfill modern browser features and APIs for browsers that don’t support them.&lt;/li&gt;
&lt;li&gt;Stencil uses APIs built directly within the browser instead of writing custom client-side JavaScript&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;# Creating a Stencil Project :&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Step 1: Install Stencil CLI&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;First, we need to set up the stencil CLI globally. Go to your terminal and run the below command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install -g @stencil/core
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Step 2: Create a new Stencil Project&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;To create a new Stencil Project, Go to the desired folder location and run the below command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm init stencil
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When you run the above command, it will be prompted to select the project type, Please select the component and provide a project name.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;? Select a starter project.

Starters marked as [community] are developed by the Stencil Community,
rather than Ionic. For more information on the Stencil Community, please see
https://github.com/stencil-community » - Use arrow-keys. Return to submit.
&amp;gt;   component                Collection of web components that can be used anywhere
    app [community]          Minimal starter for building a Stencil app or website
    ionic-pwa [community]    Ionic PWA starter with tabs layout and routes
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Step 3: Install Dependencies&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Navigate to your stencil project location (&lt;code&gt;cd your-stencil-project&lt;/code&gt;) and install the dependencies as shown below&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once the dependencies are installed, run the below command to make sure the Stencil project is running correctly.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; npm start
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Go to this location and check your output &lt;a href="http://localhost:33333" rel="noopener noreferrer"&gt;http://localhost:33333&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3lcz820gv18o6chjjta7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3lcz820gv18o6chjjta7.png" alt="Image description" width="800" height="184"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Creating a Web Components :&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Now let’s create a custom Web Component. For this example, we’ll create a simple Button component.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Step 1: Generating a new Component&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Go to your project location in the terminal and execute the below command to generate a new component:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm run generate
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You’ll be prompted to enter the name of your component. For this article, we name the button component as “new-button”. Enter the component name and press Enter.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt; my-stencil-project@0.0.1 generate
&amp;gt; stencil generate

[38:18.7]  @stencil/core
[38:19.1]  v4.22.1
√ Component tag name (dash-case): ... new-button
√ Which additional files do you want to generate? » Stylesheet (.css), Spec Test  (.spec.tsx), E2E Test (.e2e.ts)

$ stencil generate new-button

The following files have been generated:
  - src\components\new-button\new-button.tsx
  - src\components\new-button\new-button.css
  - src\components\new-button\test\new-button.spec.tsx
  - src\components\new-button\test\new-button.e2e.ts
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;New components will be added to your project.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F878423k08ql7pa27hmic.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F878423k08ql7pa27hmic.png" alt="Image description" width="273" height="487"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Step 2: Define the Component&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Go to your generated component file location(&lt;code&gt;src/components/new-button/new-button.tsx&lt;/code&gt;) and define your component as shown below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { Component, h,  Prop } from '@stencil/core';

@Component({
  tag: 'new-button',
  styleUrl: 'new-button.css',
  shadow: true,
})
export class NewButton {
  @Prop() text: string; 
   render() {
    return (
      &amp;lt;button&amp;gt;
         {this.text}
      &amp;lt;/button&amp;gt;
    );
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;@Prop&lt;/code&gt; decorator lets you create parameters with access to component attributes.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Step 3: Add Styles&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Add some basic styles to your component in the &lt;code&gt;new-button.css&lt;/code&gt; file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;button {
  background-color: #0056b3;
  color: white;
  border: none;
  padding: 10px 20px;
  font-size: 16px;
  cursor: pointer;
  border-radius: 4px;
}

button:hover {
  background-color:#1500ffde; 
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Step 4: Build Your Component&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Build your component by running:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm run build
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Step 5: Test your Component&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;You can test your component by adding the component name to your &lt;code&gt;index.html&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;new-button text="My First Component"&amp;gt;&amp;lt;/new-button&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Here text is the label name of your button component.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Your &lt;code&gt;index.html&lt;/code&gt; file looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;html dir="ltr" lang="en"&amp;gt;
  &amp;lt;head&amp;gt;
    &amp;lt;meta charset="utf-8" /&amp;gt;
    &amp;lt;meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=5.0" /&amp;gt;
    &amp;lt;title&amp;gt;Stencil Component Starter&amp;lt;/title&amp;gt;

    &amp;lt;script type="module" src="/build/my-stencil-project.esm.js"&amp;gt;&amp;lt;/script&amp;gt;
    &amp;lt;script nomodule src="/build/my-stencil-project.js"&amp;gt;&amp;lt;/script&amp;gt;
  &amp;lt;/head&amp;gt;
  &amp;lt;body&amp;gt;
    &amp;lt;new-button text="My Component"&amp;gt;&amp;lt;/new-button&amp;gt;
  &amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, run the below command and check the output in your browser (&lt;a href="http://localhost:33333" rel="noopener noreferrer"&gt;http://localhost:33333&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmohd22euaw5xmvx4n9xy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmohd22euaw5xmvx4n9xy.png" alt="Image description" width="800" height="152"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can find the complete source code on &lt;a href="https://github.com/sgeorge1979/my-stencil-project" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;# Integrating Web Components into Angular Application&lt;/strong&gt;&lt;br&gt;
Now that our custom Web Component is built with Stencil.js, let’s integrate it into an Angular application. For this article, we are using Angular v18.&lt;/p&gt;

&lt;p&gt;We can integrate the Stencil Web Components in different ways.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You can publish your web component as an NPM package and configure the dependency in your angular application.&lt;/li&gt;
&lt;li&gt;You can manually copy and paste the web components into your angular application and configure it based on it.&lt;/li&gt;
&lt;li&gt;You can directly integrate your stencil project into the angular application.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In this article, We are going to integrate your stencil project directly into the angular applicaion.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Create an Angular Application&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Step 1: Set Up the Environment&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Go to your terminal and install the Angular command-line interface (CLI). This will help you get up and running quickly with Angular:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install -g @angular/cli
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Step 2: Create a New Angular Project&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Once Angular CLI is installed, you can use it to create a new Angular project. Navigate to the directory where you want to create your project and run the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ng new stencil-angularapp --standalone=false
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Step 3: Add the Stencil Project as depedency in Angular Application.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Now, We are going to add the stencil project in our Angular Application as a depedency.&lt;/p&gt;

&lt;p&gt;Open your tsconfig.json from your angular project (stencil-angularapp) and include relative path of your Stencil Project under compilerOptions like below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    "paths": {
         "@web-components/*": ["../my-stencil-project/*"]
     }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now create a folder called /libs/stencil-generated under the src folder this is where we will use the typescript path feature for keeping the stencil project as its dependency.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fg5i2o811andcde253wzx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fg5i2o811andcde253wzx.png" alt="Image description" width="298" height="133"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now add an angular module from we will export our components inside this libs directory like below, We are creating a module called&lt;code&gt;web-components.module.ts&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcqkcv1xindgnbvpfls7s.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcqkcv1xindgnbvpfls7s.png" alt="Image description" width="800" height="499"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We are done with the basic configuration, Now we need to configure the stencil project to copy the component into the angular application.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Adding the Angular Output Target&lt;/strong&gt;&lt;br&gt;
Go to your stencil project and Install the &lt;code&gt;@stencil/angular-output-target&lt;/code&gt;dependency to your Stencil component library package.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install @stencil/angular-output-target --save-dev
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In your project’s &lt;code&gt;stencil.config.ts&lt;/code&gt;, add the &lt;code&gt;angularOutputTarget&lt;/code&gt; configuration to the &lt;code&gt;outputTargets&lt;/code&gt; array:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { Config } from '@stencil/core';
// New Import
import { angularOutputTarget, ValueAccessorConfig  } from '@stencil/angular-output-target';

// props binding
const angularValueAccessorBindings: ValueAccessorConfig[] = [];

export const config: Config = {
  namespace: 'my-stencil-project',
  outputTargets: [
    {
      type: 'dist',
      esmLoaderPath: '../loader',
    },
    {
      type: 'dist-custom-elements',
      customElementsExportBehavior: 'auto-define-custom-elements',
      externalRuntime: false,
    },
    {
      type: 'docs-readme',
    },
    {
      type: 'www',
      serviceWorker: null, // disable service workers
    },
    // Newly Added Target
    angularOutputTarget({
      componentCorePackage: '', // Update the path
      directivesProxyFile: '', // Update the path
      valueAccessorConfigs: angularValueAccessorBindings,
    })
  ],
  testing: {
    browserHeadless: "new",
  },
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now update angularOutputTarget with relative paths of your angular application.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;angularOutputTarget({
      componentCorePackage: '@web-components/dist/components', 
      directivesProxyFile: './../stencil-angularapp/src/libs/stencil-generated/proxies.ts', 
      valueAccessorConfigs: angularValueAccessorBindings,
    })
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, build the stencil project with the following command.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm run build
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once the build is successful you would see the stencil-generated folder in your angular application is populated with some files.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8oqsvjdak0x5qskmpmir.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8oqsvjdak0x5qskmpmir.png" alt="Image description" width="302" height="173"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you notice because of our tsconflg.json settings, angular is able to know what &lt;code&gt;@web-components/dist/components&lt;/code&gt; is referring to.&lt;/p&gt;

&lt;p&gt;Consume the webcomponent in your Angular Application&lt;/p&gt;

&lt;p&gt;Now we will see how to consume the webcomponents in our Application&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1: Registering Custom Elements&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;update the &lt;code&gt;web-components.module.ts&lt;/code&gt; with our component definition in the declarations and exports block.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
// Added for Component Rendering
import {defineCustomElements} from '@web-components/loader';
import { NewButton } from './stencil-generated/proxies';

defineCustomElements(window);  // Added for rendering the component 
                                  in the browser


@NgModule({
  declarations: [NewButton],   // Declare the Webcomponent
  imports: [
    CommonModule
  ],
  exports: [NewButton]        // Ecport the Webcomponent         
})
export class WebComponentsModule { }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Please note that *&lt;em&gt;declareCustomElements *&lt;/em&gt;(not declareCustomElement) is used to initate the loader to load the custom web component , This line is very important without which the browser would render nothing.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;em&gt;Step2 : Update your Angular component&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Now , we are going to consume the web components in our angular application module and HTML file.&lt;/p&gt;

&lt;p&gt;Update your &lt;code&gt;app.module.ts&lt;/code&gt; by importing the &lt;code&gt;WebComponentsModule&lt;/code&gt;as shown below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { WebComponentsModule } from '../libs/web-components.module'; // Add webcomponent

import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';

import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    AppRoutingModule,
    WebComponentsModule   // Import it here 
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now update &lt;code&gt;app.component.html&lt;/code&gt; to consume your webcomponent.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  &amp;lt;div class="content"&amp;gt;
    &amp;lt;h1&amp;gt;Integrating the Stencil WebComponent&amp;lt;/h1&amp;gt;
    &amp;lt;hr&amp;gt;
     &amp;lt;new-button text="My First Component"&amp;gt;&amp;lt;/new-button&amp;gt;
  &amp;lt;/div&amp;gt;

&amp;lt;router-outlet /&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;run the angular app in dev mode&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ng serve
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Open &lt;code&gt;http://localhost:4200&lt;/code&gt; in your browser and check your webcomponent output.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7gqk53zsxy6yn09wj9fb.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7gqk53zsxy6yn09wj9fb.gif" alt="Image description" width="600" height="344"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can find the complete Angular application source code on &lt;a href="https://github.com/sgeorge1979/stencil-angularapp" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Stencil offers a powerful way to build reusable and performant components that can be easily integrated into Angular applications. If you’re looking for a solution that promotes framework independence, performance optimization, and better component reusability, Stencil is a great option to consider.&lt;/p&gt;

&lt;p&gt;Hope this article is useful to you and your project, If you like this article, &lt;a href="https://dev.to/sudhakar_george_e6d1f136f/integrating-stencil-web-components-in-angular-project-f9b"&gt;like &amp;amp; share&lt;/a&gt; it with your friends.&lt;/p&gt;

&lt;p&gt;Follow Me for more articles.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Integrating the Copyright Component in an Angular Application</title>
      <dc:creator>Sudhakar George</dc:creator>
      <pubDate>Sun, 03 Nov 2024 18:16:37 +0000</pubDate>
      <link>https://dev.to/sudhakar_george_e6d1f136f/integrating-copyright-component-in-angular-application-jb9</link>
      <guid>https://dev.to/sudhakar_george_e6d1f136f/integrating-copyright-component-in-angular-application-jb9</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fg270ins4wjmg88uzbcf0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fg270ins4wjmg88uzbcf0.png" alt="Image description" width="800" height="260"&gt;&lt;/a&gt;A “copyright functionality” on a website refers to the practice of displaying a copyright notice, typically in the footer, which indicates that the content on the site is protected by copyright and belongs to the website owner, usually including the copyright symbol, the year of publication, and the owner’s name, essentially informing users that they cannot copy or use the content without permission&lt;/p&gt;

&lt;p&gt;I created a copyright component; developers just need to use the tag based on their needs. In this article, we will go over how to integrate the Copyright component with an Angular Application in detail.&lt;/p&gt;

&lt;h2&gt;
  
  
  Adding sg-copyright package
&lt;/h2&gt;

&lt;p&gt;Step1: Add the sg-copyright package to your application&lt;/p&gt;

&lt;p&gt;In your Angular application go to the root folder and install the sg-copyright library via npm. This will install the latest version of the library:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm i sg-copyright 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once the package is installed successfully, Your &lt;strong&gt;package.json&lt;/strong&gt; will be updated with the sg-copyright package.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5oz538yuf2p32c60c0x7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5oz538yuf2p32c60c0x7.png" alt="Image description" width="670" height="412"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Step2: Configure the main.js file&lt;/p&gt;

&lt;p&gt;Add an import to &lt;strong&gt;main.js&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And somewhere near the bottom, we’ll call this function.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;defineCustomElements();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;your &lt;strong&gt;main.js&lt;/strong&gt; file looks like this&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppModule } from './app/app.module';

import { defineCustomElements} from '../node_modules/sg-copyright/loader';

platformBrowserDynamic().bootstrapModule(AppModule, {
  ngZoneEventCoalescing: true
})
  .catch(err =&amp;gt; console.error(err));
  defineCustomElements(); 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Step3: Update the app.module.ts file&lt;/p&gt;

&lt;p&gt;Next, in app.module.ts add the &lt;strong&gt;CUSTOM_ELEMENTS_SCHEMA&lt;/strong&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import {CUSTOM_ELEMENTS_SCHEMA} from `@angular/core`;
and then

schemas: [
    CUSTOM_ELEMENTS_SCHEMA
]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Your &lt;strong&gt;app.module.ts&lt;/strong&gt; should look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { NgModule, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';

@NgModule({
  declarations: [],
  imports: [],
  schemas: [ CUSTOM_ELEMENTS_SCHEMA],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Please Note: schemas: [ CUSTOM_ELEMENTS_SCHEMA ] need to be added to each component where you are using custom HTML tags.&lt;br&gt;
Say, for example, if you use the &lt;strong&gt;sg-copyright&lt;/strong&gt; in your footer component, then your footer component looks like this.&lt;/p&gt;


&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { Component } from '@angular/core';
import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
@Component({
  selector: 'app-footer',
  standalone: true,
  imports: [],
  schemas: [ CUSTOM_ELEMENTS_SCHEMA ],
  templateUrl: './footer.component.html',
  styleUrl: './footer.component.css'
})
export class FooterComponent {
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/blockquote&gt;

&lt;p&gt;Step4: Consume the component in html file&lt;/p&gt;

&lt;p&gt;Now consume the component in your HTML file (footer component)as show below&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;sg-copyright placement="center" from="2020" company="ABCD Crop" locale="en" color="#ffffff"&amp;gt;&amp;lt;/sg-copyright&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can configure the component based on your application style. Here all parameters are optional.&lt;/p&gt;

&lt;p&gt;You can also find the sg-copyright information on npm website.&lt;/p&gt;

&lt;p&gt;Example&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; &amp;lt;footer id="footer"&amp;gt;
   &amp;lt;div class="rodape"&amp;gt;
     &amp;lt;sg-copyright placement="center" from="2020" company="ABCD Crop" locale="en" color="#ffffff"&amp;gt;&amp;lt;/sg-copyright&amp;gt;
   &amp;lt;/div&amp;gt;
  &amp;lt;/footer&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnb0gpz3khhjywn4s5f38.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnb0gpz3khhjywn4s5f38.png" alt="Image description" width="800" height="67"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This sg-copyright copyright has different options, you can configure it based on your needs.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fo9oizc3haqc1jenkrghp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fo9oizc3haqc1jenkrghp.png" alt="Image description" width="800" height="480"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;     sg-copyright components options
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;I hope this article is useful to you and your project, If you like this article, &lt;a href="https://dev.to/sudhakar_george_e6d1f136f/integrating-copyright-component-in-angular-application-jb9"&gt;like &amp;amp; share&lt;/a&gt; it with your friends.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/sudhakar_george_e6d1f136f"&gt;Follow Me&lt;/a&gt; for more articles.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Load PDF file in Angular</title>
      <dc:creator>Sudhakar George</dc:creator>
      <pubDate>Tue, 15 Oct 2024 13:52:21 +0000</pubDate>
      <link>https://dev.to/sudhakar_george_e6d1f136f/load-pdf-file-in-angular-573d</link>
      <guid>https://dev.to/sudhakar_george_e6d1f136f/load-pdf-file-in-angular-573d</guid>
      <description>&lt;p&gt;&lt;strong&gt;Load PDF file in Angular&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In most projects one common requirement is to load and view PDF documents directly within the application. There are differents ways we can achive this, In this article, I will walk through the process of integrating an angular application using ngx-extended-pdf-viewer a third-party package.&lt;br&gt;
Please note that for this article i am using Angular 18.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1: Set Up the Environment&lt;/strong&gt;&lt;br&gt;
Go to your terminal and install the Angular command-line interface (CLI). This will help you get up and running quickly with Angular:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; npm install -g @angular/cli
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 2: Create a New Angular Project&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Once Angular CLI is installed, you can use it to create a new Angular project. Navigate to the directory where you want to create your project and run the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ng new ngx-pdf-viewer  --no-standalone
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 3: Serve Your Angular Application:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;After the project is created, navigate into the project directory then use an Angular CLI to serve your application locally by running:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ng serve
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The project is running on localhost:4200&lt;/p&gt;

&lt;p&gt;Output will be like this&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbfu4ic09xob2hk3ibvoi.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbfu4ic09xob2hk3ibvoi.png" alt="Image description" width="800" height="404"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;# Adding ngx-extended-pdf-viewer package&lt;/strong&gt;&lt;br&gt;
Step1 : Add the ngx-extended-pdf-viewer&lt;/p&gt;

&lt;p&gt;Run the command below to install the &lt;code&gt;ngx-extended-pdf-viewer&lt;/code&gt; library via npm. This will install the latest version of the library:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install ngx-extended-pdf-viewer
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once the package is installed successfully, Your &lt;code&gt;package.json&lt;/code&gt; will be updated with the &lt;code&gt;ngx-extended-pdf-viewer&lt;/code&gt; package.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnqvj3ejcl0nmd6ia52o2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnqvj3ejcl0nmd6ia52o2.png" alt="Image description" width="532" height="336"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step2: Configure the angular.json file&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Now you need to configure the angular.json file. You’ll add this configuration under the&lt;code&gt;projects &amp;gt; yourProjectName &amp;gt; architect &amp;gt; build &amp;gt; options &amp;gt; assets&lt;/code&gt; section:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  "input": "node_modules/ngx-extended-pdf-viewer/assets/",
  "output": "/assets/"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Your angular.json looks like this&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fx9c3xg8kl7dkk6kiv61c.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fx9c3xg8kl7dkk6kiv61c.png" alt="Image description" width="720" height="405"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 3: Configure the application module:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Go to the &lt;code&gt;app.module.ts&lt;/code&gt; file and import &lt;code&gt;NgxExtendedPdfViewerModule&lt;/code&gt; from &lt;code&gt;ngx-extended-pdf-viewer&lt;/code&gt; and pass it to the imports array:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { NgxExtendedPdfViewerModule } from 'ngx-extended-pdf-viewer'; 

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    AppRoutingModule,
    NgxExtendedPdfViewerModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 4: Load the PDF document :&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Add your PDF files in the &lt;code&gt;src/assets&lt;/code&gt; directory as shown below:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcv7bwt0h820vvxtbi9x4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcv7bwt0h820vvxtbi9x4.png" alt="Image description" width="217" height="287"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now load the PDF file in your &lt;code&gt;app.component.html&lt;/code&gt; file as shown below&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;ngx-extended-pdf-viewer [src]="'assets/pdf/sample_file.pdf'"&amp;gt;&amp;lt;/ngx-extended-pdf-viewer&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Your output will be like this&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3qpv91136wkf53tky1ne.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3qpv91136wkf53tky1ne.gif" alt="Image description" width="600" height="260"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can find the complete source code in &lt;a href="https://github.com/sgeorge1979/ngx-pdf-viewer-angular" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;# Enhancing the PDF Viewer&lt;/strong&gt;&lt;br&gt;
There are many configuration options you can use. You can see all the options on the ngx-extended-pdf-viewer website.&lt;/p&gt;

&lt;p&gt;Say for example you want to change the zoom size and the height of the pdf view, you can do so by adding the configuration parameters as shown below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; &amp;lt;ngx-extended-pdf-viewer [src]="'assets/pdf/sample_file.pdf'"
      [height]="'90vh'" zoom="30%"&amp;gt;
    &amp;lt;/ngx-extended-pdf-viewer&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt;&lt;strong&gt;Conclusion:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In this article, we explored how to leverage the PDF viewer to load and view PDFs within Angular applications using the external packages.&lt;/p&gt;

&lt;p&gt;Hopefully, this article is useful to you and your project.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Integrating Angular with Contentstack</title>
      <dc:creator>Sudhakar George</dc:creator>
      <pubDate>Thu, 03 Oct 2024 19:25:54 +0000</pubDate>
      <link>https://dev.to/sudhakar_george_e6d1f136f/integrating-angular-with-contentstack-4657</link>
      <guid>https://dev.to/sudhakar_george_e6d1f136f/integrating-angular-with-contentstack-4657</guid>
      <description>&lt;p&gt;Integrating Angular with Contentstack allows you to build powerful and dynamic web applications powered by a headless CMS.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is ContentStack?
&lt;/h2&gt;

&lt;p&gt;Contentstack is a headless content management system (CMS) that helps businesses manage content across multiple digital channels. It's designed to help companies create unique digital experiences, accelerate growth, and lower the cost of ownership.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Features&lt;/strong&gt;
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;em&gt;Headless&lt;/em&gt;&lt;br&gt;
 Contentstack is not tied to a specific presentation layer, so it can serve content to any channel, such as websites, mobile apps, or marketing kiosks.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;em&gt;API-based&lt;/em&gt;&lt;br&gt;
Contentstack allows developers and content managers to work independently and simultaneously to create and manage content&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;em&gt;Integrations&lt;/em&gt;&lt;br&gt;
Contentstack can connect with other tools and platforms, such as Marketo, Salesforce, and Google Analytics&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  How to integrate Contentstack with Angular:
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Step 1&lt;/strong&gt;: Create an Angular Project&lt;/p&gt;

&lt;p&gt;Steps to create Angular Project from Scratch:&lt;/p&gt;

&lt;p&gt;&lt;em&gt;1) Install Angular CLI:&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Angular CLI (Command Line Interface) is a powerful tool for creating and managing Angular projects. You can install it globally using npm by running the following command in your terminal or command prompt:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm install -g @angular/cli&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;2) Create a New Angular Project:&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Once Angular CLI is installed, you can use it to create a new Angular project. Navigate to the directory where you want to create your project and run the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ng new angular-contentstack-example --no-standalone
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;3) Serve Your Angular Application:&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;After the project is created, navigate into the project directory then use an Angular CLI to serve your application locally by running:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ng serve
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt;&lt;strong&gt;Step 2&lt;/strong&gt;: Add and Configure Contentstack Angular Module&lt;/p&gt;

&lt;p&gt;1) You need to start by installing the JavaScript SDK. Navigate to the root folder and run the following command:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm install --save contentstack&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Your package.json will be updated with the contentstack dependency as shown below:&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fftvge0sj1qc6qui6703s.png" alt="Image description" width="518" height="317"&gt;
&lt;/h2&gt;

&lt;p&gt;2) Create ContentStack Module and Service&lt;/p&gt;

&lt;p&gt;Create a &lt;code&gt;src/modules/contentstack&lt;/code&gt; folder to add the ContentStack Modules and Service. It have following 3 files.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;config.ts&lt;/li&gt;
&lt;li&gt;contentstack.module.ts&lt;/li&gt;
&lt;li&gt;contentstack.service.ts&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Faosuecxutfs0dpbbd9h4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Faosuecxutfs0dpbbd9h4.png" alt="Image description" width="373" height="377"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;1) config.ts&lt;/p&gt;

&lt;p&gt;It is a configuration file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { Injectable } from '@angular/core';

@Injectable()
export class Config {
    api_key: string;
    access_token: string;
    environment?: string;
  }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;2) contentstack.module.ts&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { ModuleWithProviders, NgModule, InjectionToken } from '@angular/core';
import { CommonModule } from '@angular/common';
import { ContentstackService} from './contentstack.service';
import { Config } from './config';
export const CsbaseAppConfigToken = new InjectionToken&amp;lt;string&amp;gt;('CsbaseAppConfigToken');

export function _csbaseAppFactory(config) {
  try {
      return  new ContentstackService(config);
  } catch (e) {
    return new ContentstackService(null);
  }
}

const ContentstackAppProvider = {
  provide: ContentstackService,
  useFactory:  _csbaseAppFactory,
  deps: [ CsbaseAppConfigToken ]
};



@NgModule({
  imports: [
    CommonModule
  ],
  declarations: [],
  providers: [ContentstackAppProvider]
})
export class ContentstackModule {

  static initializeApp(config: Config): ModuleWithProviders {
    return {
      ngModule: ContentstackModule,
      providers: [
        {provide: CsbaseAppConfigToken, useValue: config }
      ]
    };
  }

}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;3) contentstack.service.ts&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { Injectable } from '@angular/core';
import * as contentstack from 'contentstack/web';
import { Config } from './config';


@Injectable()
export class ContentstackService {
  Stack: any = {};
  stackConfig: any = {};
  constructor(private config: Config) {
    this.stackConfig = config;
    this.Stack = contentstack.Stack(config);
  }

  public stack() {
    return contentstack.Stack(this.stackConfig);
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt;3) Configure ContentStack Module in Main App&lt;/p&gt;

&lt;p&gt;Next, you need to configure the module. Add the contentstack module along with the config into your main App module:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { ContentstackModule} from '../modules/contentstack/contentstack.module';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';

const Config = {
  'api_key': 'YOUR_API_KEY',
  'delivery_token': 'YOUR_DELIVERY_TOKEN',
  'environment': 'YOUR_ENVIRONMENT'

 };

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    AppRoutingModule,
    ContentstackModule.initializeApp(Config)
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This adds the Contentstack Angular module in your App module along with the config required for retrieving data from Contentstack.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Important:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Replace &lt;strong&gt;YOUR_API_KEY&lt;/strong&gt;, &lt;strong&gt;YOUR_DELIVERY_TOKEN&lt;/strong&gt;, and &lt;strong&gt;YOUR_ENVIRONMENT&lt;/strong&gt; with your actual Contentstack credentials.&lt;/p&gt;




&lt;p&gt;4) Use the Service in your Components&lt;/p&gt;

&lt;p&gt;Inject the Contentstack Service into your components to fetch and display content:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { Component } from '@angular/core';
import { ContentstackService } from '../modules/contentstack/contentstack.service';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrl: './app.component.css'
})
export class AppComponent {
  title = 'angular-contentstack-example';
  constructor(private cs: ContentstackService) {}
  entryText:any = {};

  getEntry() {
   const Query = 
    this.cs.stack().ContentType('YOUR_CONTENT_TYPE').Query();
    Query.where('uid','YOUR_ENTRY_UID');
    Query
    .includeReference()
    .toJSON()
    .find()
    .then(
       entry =&amp;gt; {
         this.entryText = entry[0][0];
       },
       err =&amp;gt; {
         console.log(err, 'err');
       }
    ); 
}

 ngOnInit() {
  this.getEntry()
  }

}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Important:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Replace &lt;strong&gt;YOUR_CONTENT_TYPE&lt;/strong&gt;, &lt;strong&gt;YOUR_ENTRY_UID&lt;/strong&gt; with your actual Contentstack credentials.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Content Type&lt;/strong&gt;&lt;br&gt;
Content type lets you define the structure or blueprint of a page or a section of your digital property. It is a form-like page that gives Content Managers an interface to input and upload content. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Entry&lt;/strong&gt;&lt;br&gt;
An entry is the actual piece of content created using one of the defined content types. &lt;/p&gt;

&lt;p&gt;In your HTML you can iterate a data and map it according to your needs.&lt;/p&gt;

&lt;p&gt;For Example&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    @for (item of entryText.sections; track item; let index = $index) {
      &amp;lt;tr&amp;gt;
         &amp;lt;td&amp;gt;{{ index }} &amp;lt;/td&amp;gt;
         &amp;lt;td&amp;gt;{{ entryText[index].form_name}} &amp;lt;/td&amp;gt;
         &amp;lt;td&amp;gt;{{ entryText[index].script_text}}&amp;lt;/td&amp;gt;
         &amp;lt;td&amp;gt;{{ entryText[index].label}}&amp;lt;/td&amp;gt;
       &amp;lt;/tr&amp;gt; 
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
    </item>
    <item>
      <title>Generate an API document with redoc to view a local API .json file using the Angular Application</title>
      <dc:creator>Sudhakar George</dc:creator>
      <pubDate>Wed, 02 Oct 2024 16:14:52 +0000</pubDate>
      <link>https://dev.to/sudhakar_george_e6d1f136f/generate-api-document-with-redoc-to-view-a-local-api-json-file-using-angular-application-41co</link>
      <guid>https://dev.to/sudhakar_george_e6d1f136f/generate-api-document-with-redoc-to-view-a-local-api-json-file-using-angular-application-41co</guid>
      <description>&lt;p&gt;In this tutorial, I am going to create a sample Angular application to generate a API document using redoc to read a local JSON files. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1:  Create an Angular Project&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Steps to create Angular Project from Scratch:&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Step 1: Install Angular CLI:&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Angular CLI (Command Line Interface) is a powerful tool for creating and managing Angular projects. You can install it globally using npm by running the following command in your terminal or command prompt:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install -g @angular/cli
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Step 2: Create a New Angular Project:&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Once Angular CLI is installed, you can use it to create a new Angular project. Navigate to the directory where you want to create your project and run the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ng new angular-redoc --no-standalone
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Step 3: Serve Your Angular Application:&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;After the project is created, navigate into the project directory then use an Angular CLI to serve your application locally by running:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ng serve
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Folder Structure going to be like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fl8gscvdzj3h9v80xbuok.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fl8gscvdzj3h9v80xbuok.png" alt="Image description" width="282" height="702"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 2:  Add and Configure the Redoc in Angular Project&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;What is Redoc?&lt;/p&gt;

&lt;p&gt;Redoc is an open source tool for generating beautiful API documentation from OpenAPI (formerly Swagger) definitions.&lt;/p&gt;

&lt;p&gt;Redoc is a clean and easy way to produce web-ready documentations.&lt;/p&gt;

&lt;p&gt;By default Redoc offers a three-panel, responsive layout:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The left panel contains a search bar and navigation menu.&lt;/li&gt;
&lt;li&gt;The central panel contains the documentation.&lt;/li&gt;
&lt;li&gt;The right panel contains request and response examples.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;Step 1: Adding the Redoc :&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Go to the root folder and execute the following npm command to add the Redoc into the project&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm i redoc
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once you execute the command you can see the redoc is added into the package.json file&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fflhrcg2yjs07nemb4opu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fflhrcg2yjs07nemb4opu.png" alt="Image description" width="506" height="337"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Step 2: Add the Redoc Script:&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Add the script element in index.html page&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;script src="https://cdn.redoc.ly/redoc/latest/bundles/redoc.standalone.js"&amp;gt; &amp;lt;/script&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpnzzg60a4ntk1q7aqmre.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpnzzg60a4ntk1q7aqmre.png" alt="Image description" width="800" height="403"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Note: If you would instead prefer to host the depdencies yourself,You can then reference the Redoc script with a node modules link as well :&lt;br&gt;
&lt;code&gt;&amp;lt;script src="node_modules/redoc/bundles/redoc.standalone.js"&amp;gt; &amp;lt;/script&amp;gt;&lt;/code&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;em&gt;Step 3: Configure the Redoc in the component:&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Create a method to fetch the local json object and map it in the HTML file&lt;/p&gt;

&lt;p&gt;Added it in your component:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;initDocs(){
    const container = this.el.nativeElement.querySelector('#redoc');
    Redoc.init('**LOCAL JSON FILE INFORMATION**', {
     scrollYOffset: 60,
     hideDownloadButton: true
   }, container);
 }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note: Angular's ElementRef to access the native DOM element and the ngOnInit lifecycle hook to ensure that the component is ready before initializing Redoc.&lt;/p&gt;

&lt;p&gt;Here is the complete code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { Component, ElementRef, OnInit } from '@angular/core';
declare var Redoc: any;

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrl: './app.component.css'
})
export class AppComponent implements OnInit  {
  title = 'angular-redoc';

  constructor(private el: ElementRef) { }

  ngOnInit() {
    this.initDocs();
  }



  initDocs(){
    const container = this.el.nativeElement.querySelector('#redoc');
    Redoc.init('**LOCAL JSON FILE INFORMATION**', {
    scrollYOffset: 60,
    hideDownloadButton: true
   }, container);
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Step 4: Read the JSON file from the local directory:&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Create a Json file and place it in your assert folder.&lt;/p&gt;

&lt;p&gt;You can find the sample Json file in the following location&lt;br&gt;
 &lt;code&gt;http://petstore.swagger.io/v2/swagger.json&lt;/code&gt;  &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffgikzrcxsjd8cbzy5rc7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffgikzrcxsjd8cbzy5rc7.png" alt="Image description" width="365" height="141"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Note: It is not possible to call the local JSON file directly due to  same-origin policy restrictions&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Step 5: Call the local Json file from the component:&lt;/em&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Using the import statement
One way to read a JSON file from the assets folder in Angular is to use the import statement in your component.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Eg:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import * as sampleJsonData from '../assets/redoc-sample.json';
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;You need to add &lt;strong&gt;"resolveJsonModule": true&lt;/strong&gt; in the compilerOptions of your tsconfig.json the file that is at the root of your Angular application.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "compileOnSave": false,
  "compilerOptions": {
    "baseUrl": "./",
    "resolveJsonModule": true
  },
  "angularCompilerOptions": {
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Declare a variable and assign the JSON object in a new variable called data.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;code&gt;data: any = sampleJsonData ;&lt;/code&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Set the local file name&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Replace the '&lt;strong&gt;LOCAL JSON FILE INFORMATION&lt;/strong&gt;' with the assigned variable (this.data) as seen below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  initDocs(){
    const container = this.el.nativeElement.querySelector('#redoc');
    Redoc.init(this.data, {
    scrollYOffset: 60,
    hideDownloadButton: true
   }, container);
  }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Map the HTML file with the selector name:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;     &amp;lt;div id="redoc"&amp;gt;&amp;lt;/div&amp;gt; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fd1l60vpfd2m9uu5dt5n2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fd1l60vpfd2m9uu5dt5n2.png" alt="Image description" width="800" height="356"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Thats it !!&lt;/p&gt;

&lt;p&gt;Your output will be something like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2pp5yd8p60npnivjn7ke.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2pp5yd8p60npnivjn7ke.png" alt="Image description" width="800" height="351"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
