2

So I'm building this Pencilblue website. Pencilblue is based on the MEAN stack.

I'm trying to get a search function going. I need to declare a module.

Pencilblue does it like this:

ClientJs.getAngularController = function(objects, modules, directiveJS) {
    if(!util.isArray(modules) || modules.length > 0) {
        modules = ['ngRoute'];
    }

    var angularController = 'var pencilblueApp = angular.module("pencilblueApp", ' + JSON.stringify(modules) + ')';

So the 2nd line is telling me the modules are loaded from somewhere else, unless there are none, in which case, the modules = ['ngRoute']; should be loaded.

What I came up with is this:

ClientJs.getAngularController = function(objects, modules, directiveJS) {
        if( modules.length > 0) {
            modules = ['ngRoute', 'elasticui'];
        }

        var angularController = "var pencilblueApp = angular.module('pencilblueApp', " + JSON.stringify(modules) + ").constant('euiHost', 'localhost:9200')";

While this works, I'm not sure it's an orthodox way of doing it and I might need to add others in the future. I'd really appreciate if someone could help out and tell me the right way to add this ['elasticui'] module in Pencilblue, together with the last part, the .constant('euiHost', 'localhost:9200')";

I'm adding ElasticUI to my project, and the only thing that I had problems with was adding this step: angular.module('yourApp', ['elasticui']).constant('euiHost', 'http://localhost:9200');

It's rather trivial to do it in a MEAN stack or plain Angular.js, but it's quite confusing in Pencilblue.

Would really appreciate a detailed response on how to do this the proper way. Thanks.

Andrei Stefan
  • 51,654
  • 6
  • 98
  • 89
user19882
  • 113
  • 7
  • I'm personally not a great fan of how PB handles Angular, as it's split up between PB controllers injecting data into templates that contain the actual Angular code, which is then added to the page template. For my custom news page I created a custom controller that uses a custom template and then did it the good old way of adding everything related to Angular in an external JS file and loading that in. – Chris Satchell Jul 09 '16 at 11:05

0 Answers0