I would pass a string version of the array and then parse it on the client:
app.get('/', function(req, res) { res.render('index', { names: JSON.stringify(["Daniel", "Sarah", "Peter"]) }); });
And don't forget to specify it (this assumes your controller is on your EJS page)!
.controller('NamesController', function ($scope) { var info = JSON.parse('<%= names %>'); });
If your controller is in your own file, you can use the ngInit method:
<div ng-init="init('<%= names %>')"></div>
And analyze:
$scope.init = function(stringifiedArray) { var info = JSON.parse(stringifiedArray); }
tymeJV
source share