How can i share data between express.js and angular.js , am using ejs view engine in express.js . in case if i want share data to in the root page of angular.js i can simply use :
<%= {{variable from express.js}} %>
Note
meaning of root page of angular.js page is the target page of route in express.js . in my example is index.ejs.
Question
but what if i want use the variable or array in express.js inside a directive template of angular.js ??
Example :
index.js
var mysql = require('mysql');
exports.index = function (req, res) {
var connection = mysql.createConnection({
host: '*****',
user: '*****',
password: '******',
insecureAuth: true
});
connection.connect();
connection.query('select * from asterisk.queue_log limit 10', function (err, rows, fields) {
if (err) throw err;
console.log(rows);
res.render('index', {
values: rows,
title: 'Express',
});
});
connection.end();
};
Angular directive template
<div class="half-unit bg-light-ltr" ng-repeat="active in ActiveCalls">
<dtitle>{{active.queueName}}</dtitle>
<hr>
<div>
</div>
<h2>{{values}} <!--<i class="fa fa-arrow-up {{test}}"></i>--></h2>
<p>
<img src="images/up-small.png" alt=""> 412 Max. |
<img src="images/down-small.png" alt=""> 89 Min.
</p>
</div>
NOTE
I can use ng-init="values='<%= values%>'" in the root page of angular (index.ejs) and then use values array in directive template . am asking if there is a better way doing that .