node-red-dashboard template node and ng-controller

615 views
Skip to first unread message

Jérôme

unread,
Feb 2, 2017, 8:12:38 AM2/2/17
to Node-RED
Hi,

I'm kind of new to angular, not so much to node-red.
I'm trying some things with the template node of node-red-dashboard and I'm stuck with trying to add a new controller.

If i'm doing something like this, it works like a charm :
<div ng-cloak="">
  <md-button ng-style="{background: msg.payload=='0' ?'green':'red'}" ng-click="send({payload: test()})">Payload {{msg.payload}}</md-button>
  
  <br>
  <md-button ng-click="togglePayLoad()">Toggle Payload</md-button>
</div>
<script>
    (function(scope){ 
      scope.togglePayLoad = function () {
        scope.msg.payload = (scope.msg.payload === 0) ? 1 : 0;
      }
      scope.test = function() {
          return {bla: 42} ;
      }
  })(scope);
</script>

If I want to add a new controller to the main app, it always fails, whatever I try to do. Same code with ng-controller and it's definition :
<div ng-cloak="">
  <md-button ng-controller="Test" ng-style="{background: msg.payload=='0' ?'green':'red'}" ng-click="send({payload: test()})">Payload {{msg.payload}}</md-button>
  
  <br>
  <md-button ng-click="togglePayLoad()">Toggle Payload</md-button>
</div>
<script>
    (function(scope){ 
      scope.togglePayLoad = function () {
        scope.msg.payload = (scope.msg.payload === 0) ? 1 : 0;
      }
      scope.test = function() {
          return {bla: 42} ;
      }
  })(scope);
  angular.module('foo', []).controller('Test', Test);
  function Test() { return 42; }
</script>

with the error :
The controller with the name 'Test' is not registered.

Anyway to achieve that with the template node ?

Thanks,
-- 
Jérôme

Julian Knight

unread,
Feb 4, 2017, 7:38:25 PM2/4/17
to Node-RED
AFAIK, you can't add or access the controller in the Dashboard, it is hidden away.

You would need to create a separate Angular app for yourself and use the http nodes - probably along with a manually created websocket node.
Reply all
Reply to author
Forward
0 new messages