Ir al contenido principal

How to create an AEM component using Angularjs

If you want to create an AEM app using Angular.js components and add them into a page, in this series, you will learn how. Above is the vid and below you will find some useful notes. In the second part we will see How to configure the Sling Model for the AEM Angularjs component.
  1. 1.

    Pre-reqs

  2. 2.

    Creating an AEM application with Angular.js support

    • You will need Adobe's archetype for creating your AEM application with SPA support. The support was added starting from the 23rd version of the archetype.
    • So let’s create the app from scratch. I am providing the most important properties in a single line here given that the other properties will be inferred from them, notice that the frontendModule property was set to angular
      mvn -B archetype:generate `
          -D archetypeGroupId=com.adobe.granite.archetypes `
          -D archetypeArtifactId=aem-project-archetype `
          -D archetypeVersion=23 `
          -D aemVersion=6.5.0 `
          -D appTitle="Angularjs Simple Example" `
          -D appId="angularjs-simple-example" `
          -D groupId="co.dlighthouse.aem.angularjs.simpleexample" `
          -D frontendModule=angular `
          -D includeExamples=y `
          -D includeDispatcherConfig=n
      
    • Let’s build and deploy our new app (make sure that you have AEM up and running)
      mvn clean install -PautoInstallPackage -Padobe-public
      
  3. 3.

    AEM component using angularjs

    • For creating an AEM component using angular we need at least 4 things, a skeleton AEM component with a dialog, a angular component, an entry importing the component inside the app.module.ts file and a sling model which I’ll be configuring in the next video.
    • I am going to use the yeoman generator for creating the skeleton AEM component for me with some additional example fields in the dialog. I am calling it basic-component and I am making sure that the names for the folders and component group match my current application’s configuration.
      yo aem-application:aem-component `
          mavenAppsModuleName=ui.apps `
          componentParentPath=angularjs-simple-example/components `
          componentNodeName=basic-component `
          componentName="Basic Component" `
          componentGroup="Angularjs Simple Example - Content" `
          mavenBundleModuleName=core `
          javaRootPackageName=co.dlighthouse.aem.angularjs.simpleexample.core `
          javaModelRelativePackageName=models `
          javaModelClassName=BasicModel
      
    • We should end up with a component inside componentParentPath=angularjs/components called Basic Component, if you check the dialog’s xml file you will find two example fields, one for the text and another for the checkbox.
      <items
        jcr:primaryType=\"nt:unstructured\">
          <text
              jcr:primaryType=\"nt:unstructured\"
              sling:resourceType=\"granite/ui/components/coral/foundation/form/textfield\"
              fieldLabel=\"Text\"
              name=\"./text\"/>
          <checkbox
              jcr:primaryType=\"nt:unstructured\"
              sling:resourceType=\"granite/ui/components/coral/foundation/form/checkbox\"
              text=\"Checkbox\"
              uncheckedValue=\"false\"
              value=\"true\"
              name=\"./checkbox\"/>
          <checkboxType
              jcr:primaryType=\"nt:unstructured\"
              sling:resourceType=\"granite/ui/components/foundation/form/hidden\"
              name=\"./checkbox@TypeHint\"
              value=\"Boolean\"/>
      </items>
      
    • Before creating the component make sure that you have the Angular command-line interface (CLI) by first installing it in your computer
      npm install -g @angular/cli
      
    • Use the Angular.js CLI to create the component inside the components folder.
      ng generate component components/basic-component
      
      In the ui.frontend module you will find the Angular.js components inside the src/app/components folder. Add the imports for the Input annotation object from the angular/core library and the MapTo helper from adobe.
      import { Component, Input, OnInit } from '@angular/core';
      import { MapTo } from '@adobe/cq-angular-editable-components';
      
    • Create an editconfig obj which will be used for displaying some text when the component is empty, in this case given that the component’s properties like the ones defined on the dialog are available through the angular’s cqModel object we can just check if cqModel.text doesn’t have a value so that we can mark this component as empty
      const BasicComponentEditConfig = {
        emptyLabel: 'Basic Component',
        isEmpty: cqModel =>
          !cqModel || !cqModel.text || cqModel.text.trim().length < 1
      };
      
    • Then we have the component which looks like a typical angular component. Here we declare that we are going to receive the text and checkbox properties.
      
      export class BasicComponentComponent implements OnInit {
        @Input() text: string;
        @Input() checkbox: boolean;
      ...
      
    • Finally we call the MapTo helper function that maps the angular component to a particular resourceType inside AEM so that aem knows which angular component to use when rendering our page
      MapTo('angularjs-simple-example/components/basic-component')(
        BasicComponentComponent,
        BasicComponentEditConfig
      );
      
    • Then inside the app.module.ts file we just add an entry into the entryComponents array given that the basic component is added dynamically.
      
      @NgModule({
        ...
        entryComponents: [TextComponent, PageComponent, BasicComponentComponent],
        ...
      })
      export class AppModule {}
      
    • Build and deploy the application again
      mvn clean install -PautoInstallPackage -Padobe-public
      
  4. 4.

Comentarios

  1. How ignore the html from ui.apps? , because in my project always takes the ui.apps html and not my ui.frontend html component

    ResponderEliminar
  2. Our 2022 evaluation of Casino JackpotCity exhibits that all of the supported titles are powered by Microgaming, one of the main software program corporations in the playing trade. With Microgaming, https://casino.edu.kg/%EC%A0%95%EC%B9%B4%EC%A7%80%EB%85%B8.html gamers can take pleasure in broad range|a variety} of slots, table and card video games and different titles and there are always great betting options would possibly be} supported. The casino provides instant-play access, software program download and a mobile casino app.

    ResponderEliminar

Publicar un comentario

Entradas populares de este blog

How to copy files from and to a running Docker container

Sometimes you want to copy files to or from a container that doesn’t have a volume previously created, in this quick tips episode, you will learn how. Above is the vid and below you will find some useful notes. 1. Pre-reqs Have Docker installed 2. Start a Docker container For this video I will be using a Jenkins image as an example, so let’s first download it by using docker pull docker pull jenkins/jenkins:lts

How to create an AEM component using Reactjs

In this tutorial, I will show how to use use Adobe's archetype to create an AEM application with React.js support and also how to add a new React.js component so that it can be added into a page, above is the vid and below you will find some useful notes. In the second part we will see how to configure the Sling Model for the AEM React component. 1. Pre-reqs Have access to an Adobe Experience Manager instance. You will need aem 6.4 Service Pack 2 or newer. Have Maven installed, understand how it works and also understand how to use Adobe's archetype, you can watch my video about maven here: Creating an AEM application using Maven and Adobe's archetype 2.

House price prediction 3/4: What is One Hot Encoding

A series about creating a model using Python and Tensorflow and then importing the model and making predictions using Javascript in a Vue.js application, above is the vid and below you will find some useful notes. Here, in part 3 of this series, I will show what is and how does one hot encoding works. In the first post, called House price prediction 1/4: Using Keras/Tensorflow and python , I talked about how to create a model in python, pre-process a dataset I've already created, train a model, post-process, predict, and finally about creating different files for sharing some information about the data for use on the second part. Then in part 2, called House price prediction 2/4: Using Tensorflow.js, Vue.js and Javascript , I took the model, the data for pre and post processing and after loading everything we were finally able to predict