Mobile Apps - Component referred using reference component - JSON not set in scope | Community
Skip to main content
Level 4
September 27, 2016
Solved

Mobile Apps - Component referred using reference component - JSON not set in scope

  • September 27, 2016
  • 5 replies
  • 2964 views

Mobile Apps based implementation provides ability to integrate angular with AEM and to pass data to angular scope from AEM using angular.json.jsp and controller.js.jsp. When I am using this as standalone component and dragging to page which is based on angular template. The JSON created in angular.json.jsp is successfully read in controller.js.jsp with "frameworkType=angular"

When this component is authored in a separate page, in another page trying to use this inside reference component, the angular.json.jsp, controller.js.jsp is not coming to picture at all.

I had a use case to author the JSON structure (to be passed to angular scope) in one place, then use in all pages using reference component. Any pointers would be helpful

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by brucelef

Hi Sandeep,

The best recommendation I can offer at this point is to create an extension of the /libs/foundation/components/reference component that includes the cq:template node specifying frameworkType: angular, and supports proxying angular.json and controller.js requests to the "referenced" resource. I hacked together an example component to prove this out:

Mobile reference component example · GitHub

Hope this helps,

Bruce

5 replies

Adobe Employee
September 29, 2016

Hi Sandeep,

Can you clarify what you mean by this? Providing a piece of sample code to reproduce the issue would be very helpful.

Level 4
September 29, 2016

Hi Bruce

As part of component (say mycomponent), I have angular.json.jsp with some json content (In actual functionality this would be constructed through dialog properties)

{

    items:

[

        {

            'content': 'contentValue',

            'another': 'anotherValue'

        }

    ]

}

In controller.js.jsp there is a javascript promise from page component (similar to implementation in /libs/mobileapps/components/angular)

data.then(function(response) {

        $scope.<c:out value="${componentDataPath}"/> = response.data["<c:out value='${componentPath}'/>"].items;

  });

Now this component (this has frameworkType=angular property) is dragged in angular based template. There JSON from angular.json.jsp is set to $scope. This works fine in normal page.

Now say if I have 3 pages (Page1, Page2, Page3).In page 1 I have mycomponent dragged. In Page2, Page3, I drag reference component (/libs/foundation/components/reference). In both pages I refer to mycomponent authored in Page1. But here the call is not made to controller.js.jsp (Prob because reference node is not having frameworkType=angular). I was trying to have json in one page and refer in other 2 pages.

{    items: [        {            'content': '<%= xssAPI.encodeForJSString(properties.get("text", "")) %>',            'textIsRich': '<%= xssAPI.encodeForJSString(properties.get("textIsRich", "false")) %>'        }    ]}

Level 4
September 29, 2016

Some Junk JSON got added to the post, not able to edit the post as Actions button not working for me, ignore that, would edit that part once Action starts working for me.

Adobe Employee
September 29, 2016

Thanks for the details. I'm working on reproducing it locally and will get back to you with my recommendation.

brucelefAdobe EmployeeAccepted solution
Adobe Employee
September 29, 2016

Hi Sandeep,

The best recommendation I can offer at this point is to create an extension of the /libs/foundation/components/reference component that includes the cq:template node specifying frameworkType: angular, and supports proxying angular.json and controller.js requests to the "referenced" resource. I hacked together an example component to prove this out:

Mobile reference component example · GitHub

Hope this helps,

Bruce