# \[node-red-dashboard\] Sharing code with initController

**URL:** <https://discourse.nodered.org/t/node-red-dashboard-sharing-code-with-initcontroller/39040>\
**Category:** Developing Nodes\
**Created:** [13 January 2021 06:09 UTC](https://discourse.nodered.org/t/node-red-dashboard-sharing-code-with-initcontroller/39040 "2021-01-13T06:09:39Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![yoiang](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/yoiang/32/4831_2.png) [@yoiang](https://discourse.nodered.org/u/yoiang)\
**Post date:** [13 January 2021 06:09 UTC](https://discourse.nodered.org/t/node-red-dashboard-sharing-code-with-initcontroller/39040/1 "2021-01-13T06:09:40Z")

</div>

Hey y'all!  
I have a question that's come up every now and then, I haven't made any headway and was wondering if the forum has any ideas! Understanding that the value for the `initController` option passed to `addWidget` is `eval`uated in a frontend Angular scope, passed from the backend as a **string** , this requirement means only code present at backend runtime within one's `initController` method will be included and any code not within the scope will be most likely _undefined_. This means one cannot simply call a shared piece of code from `initController`, instead it has to be copied, often duplicated!

My question is has anyone found a novel way to rectify this situation? Is there a tricky tricky Javascript way to grab functions declared within one's `initController`? Has anyone messed with appending+evaling their `initController` with a shared function and passing the result into their `addWidget` call? Is there a preprocessor that can inline marked functions before publishing?

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [14 March 2021 06:09 UTC](https://discourse.nodered.org/t/node-red-dashboard-sharing-code-with-initcontroller/39040/2 "2021-03-14T06:09:42Z")

</div>

Closed on 14 March 2021 06:09 UTC

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
