Keshav Keshav - 5 months ago 32
AngularJS Question

Pass jsp model object to angular create parsing error

I created jsp page and sending a model with it in model attribute.

navigation map :: ${navigationMap}


It get displayed on jsp page.output :

{"navigationMap":{"file":{"name":"test1","label":"file1","action":"file1","subNavigations":[{"name":"test2","label":"file11","action":"file11","subNavigations":null},{"name":"test3","label":"file12","action":"file12","subNavigations":null}]},"reciept":{"name":"test1","label":"reciept1","action":"reciept1","subNavigations":[{"name":"test2","label":"reciept11","action":"reciept11","subNavigations":null},{"name":"test3","label":"reciept12","action":"reciept12","subNavigations":null}]}}}


But if put this variable inside ng-init of angular like

<div ng-init="navigation=${navigationMap}">
navigation::{{navigation}}
</div>


Then there is parsing error.

angular.js:11607Error: [$parse:ueoe] http://errors.angularjs.org/1.3.14/$parse/ueoe?p0=navigation%3D%7B
at Error (native)
at http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js:6:417
at ib.peekToken (http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js:190:291)
at ib.object (http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js:199:198)
at ib.primary (http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js:189:223)
at ib.unary (http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js:196:478)
at ib.multiplicative (http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js:196:205)
at ib.additive (http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js:196:63)
at ib.relational (http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js:195:435)
at ib.equality (http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js:195:291) <div ng-init="navigation={" navigationmap":{"file":{"name":"test1","label":"file1","action":"file1","subnavigations":[{"name":"test2","label":"file11","action":"file11","subnavigations":null},{"name":"test3","label":"file12","action":"file12","subnavigations":null}]},"reciept":{"name":"test1","label":"reciept1","action":"reciept1","subnavigations":[{"name":"test2","label":"reciept11","action":"reciept11","subnavigations":null},{"name":"test3","label":"reciept12","action":"reciept12","subnavigations":null}]}}}"="" class="ng-binding">


But if I use directly than json inside ng-init then it works properly given below.

<div ng-init="navigation={'navigationMap':{'file':{'name':'test1','label':'file1','action':'file1','subNavigations':[{'name':'test2','label':'file11','action':'file11','subNavigations':null},{'name':'test3','label':'file12','action':'file12','subNavigations':null}]},'reciept':{'name':'test1','label':'reciept1','action':'reciept1','subNavigations':[{'name':'test2','label':'reciept11','action':'reciept11','subNavigations':null},{'name':'test3','label':'reciept12','action':'reciept12','subNavigations':null}]}}}">


How can I remove this parsing error ?? And how can i use jsp model object directly inside ng-init of angular ??

Answer

Pass the object inside double quotes to avoid parsing error

<div ng-init="navigation='${navigationMap}'">

Then it will work.