i have array of json objects being passed node route respective view. example:
res.render("path/to/view", { data: result, data2: result2 })
where both result , result2 arrays of json objects. in view, using them in ng-init function so: ( {{}} designates swig, have changed [[]] designate angular, in below example, using swig before using defined angular init function)
<div ng-init="init( {{ data|json }} )"> </div>
i should above example works fine, when "data" becomes large dataset, time spend on swig part - converting json (again..?). said, "data" in form of json, when remove |json swig part above, [$parse:syntax] error, , give me above line evaluated:
<div ng-init="init( [object object],[object object] )"> </div>
i have tried variations of using ng-init="init( [[ json.parse( {{ data }} ) ]] )" evaluate output json (even though output is..?) cant work.
any ideas? maybe have syntax wrong? don't understand because "data" json when pass view, can't pass directly init function without getting syntax error.
take whatever you're calling ng-init out of view , put in controller or service.
there tons of reasons not use ng-init, so angular team recommends don't use it: https://docs.angularjs.org/api/ng/directive/nginit
update
i think see you're trying do, , it's called bootstrapping. can embed data view server-side so:
<script> angular.module("app").constant("mybootstrap", {{ data.stringified }}); </script> where data.stringified stringified data. in angular can inject controllers want constant mybootstrap, same $rootscope, etc., , data available.
Comments
Post a Comment