0

I'm getting unexpected End of expression error when I pass nodejs data to to ng-init. I'm confident I'm doing it right however I'm getting the error message above

I call ng-init like so:

<body id="myPage" ng-app="myApp" ng-controller="arrCtrl" ng-init="items = <%- JSON.stringify(myitems) %>">

and the error is here

Unexpected end of expression: items = [{

Thus when I run

{{items}}

It'll display as is.

I also went ahead and declared my module in my script tag just in case like so

    <script>

        var app = angular.module('myApp', []);

        app.controller('arrCtrl', function(){
            console.log("Controller loaded");
        });

    </script>

I looked everywhere and no one seemed to have solved this issue.

Kenny Nguyen
  • 222
  • 2
  • 13
  • Are you mixing server side with client side? You should fetch the items from the server and resolve it to the controller, or use inject `$http` to the dependencies list of the controller and make an ajax request. Also `JSON.stringify` returns string, not json – Alon Eitan Oct 27 '17 at 20:22
  • Yea im mixing both. I tried fetching the items from the controller, however I keep getting syntax errors. However those errors stop when I fetch from ng-init – Kenny Nguyen Oct 27 '17 at 20:34

0 Answers0