Page 1 of 1

How do you inject a service (ie $log) into a controller within the AngularJS visual builder? -Bootstrap/AngularJS

Posted: Wed Apr 08, 2015 1:17 am
by Ravenight

eg. I would like to use the built-in $log service within one of my controllers. I do not see a way I can inject this service from within the init() function of the visual builder.

I can go into the source files - WEB_RESOURCES - app - pages - my_page_nameController.js file and add it to the APP.controller call.

e.g. codeAPP.controller('my_page_name', ['$scope', 'ApperyioHelper', controller]); /code and insert '$log', between the '$scope', and 'ApperyioHelper', tags and then again in the codefunction controller($scope, Apperyio) { /code area between $scope, Apperyio and then use the $log function and it works within the init() function.

However, doing this breaks the link between the visual builder and the source file for the controller, forcing me to work only in code from then on with this controller.

I have tried using the "invoke service" button inside the init() function and then calling codeApperyio.get("$log");/code which doesn't error out. However, trying to use code$log.warn();/code afterwards does not work as $log is still undefined.

It is possible to use $log in a custom service by adding it to the codedeps: [ 'ApperyioHelper', '$log', func ]/code in the return statement. I just don't see how to inject this into the controller itself without screwing up the beautiful visual builder.


How do you inject a service (ie $log) into a controller within the AngularJS visual builder? -Bootstrap/AngularJS

Posted: Wed Apr 08, 2015 1:06 pm
by Illya Stepanov

Hi -

You will need to define it this way:
precode
var $log = Apperyio.get("$log")
/code/pre
in the controller.


How do you inject a service (ie $log) into a controller within the AngularJS visual builder? -Bootstrap/AngularJS

Posted: Sat Apr 11, 2015 12:25 pm
by Ravenight

Thanks Illya, that worked.
I logged the Apperyio object and saw the log function there. facepalm...