i want to pass a json file or object to an angular controller to use it with ng-repeat.
My json object is stored in my index.js file and written to data.json. My controller.js file looks like the following:
var fs = require('fs');
var jobs = fs.readFile('out/data.json', 'utf-8', (err, data) => {
if (err) throw err;
});
angular.module('slrm', [].controller('slrmctrl', function($scope) {
$scope.data = jobs.data;
}));
And thats my html file:
<table class="table">
<thead>
<th scope="col">#</th>
<th scope="col">JOBNAME</th>
<th scope="col">USER</th>
<th scope="col">NODE</th>
<th scope="col">CPUS</th>
<th scope="col">START</th>
<th scope="col">STATE</th>
</thead>
<tbody ng-app="slrm" ng-controller="slrmctrl">
<tr ng-repeat="x in data | orderBy : 'JOBID'">
<td>{{ x.JOBID }}</td>
<td>{{ x.NAME }}</td>
<td>{{ x.USER }}</td>
<td>{{ x.NODELIST }}</td>
<td>{{ x.CPUS }}</td>
<td>{{ x.STATE }}</td>
<td>{{ x.REASON }}</td>
</tr>
</tbody>
</table>
<script src="js/controller.js"></script>
Now I have 2 questions. Im providing this html with:
app.get('/', function (req, res) {
res.sendFile(__dirname + '/view/index.html');
});
var server = app.listen(3000, function() {
console.log('Server running');
};
Is the controller.js file even imported? because bootstrap.css is not imported somehow.
The other Question is if the line
$scope.data = jobs.data;
is even working? Should I read the file or use the exported object from index.js? How do I export only this one object?
I built this from scratch because im very new to js and stuff.
Thank you!