I'm writing a web application that will mainly use AngularJS for its modularity and testability and ASP.NET MVC server side technologies for model validation.
The idea is to load PartialView
s in ng-view
s in order to asynchronously load only specific logic parts. So the question is: how to better pass server-side objects to AngularJS controllers? A silly hack that comes to mind is to print things in the PartialView
such as:
window.myValue = 42;
and then get it back from the controller with the $window
service injected:
$scope.myValue = $window.myValue
This is not feasible, though, as ng-view
loadings strip out every <script>
tag before inserting the partial content into the DOM.
I have noticed that there is the ng-init
directive, should I rely on that one alone? Generally speaking, what are the best practices for making these two parts work with each other?
Thanks.