AngularJS + MVC : how to pass model from server to Angular controller
AngularJS + MVC : how to pass model from server to Angular controller

AngularJS + MVC : how to pass model from server to Angular controller

2014, Dec 31    

Here’s a quick tip on how to pass a complex model from server side to an AngularJS controller.
The idea is to serialize the model to json (I am using the majestic Newtonsoft library for that), store it into a javascript variable and then create a provider with it on the AngularJS application that will be injected in the controller.

Here’s the controller code:

[csharp]

myApp.controller(‘myController’, [‘$scope’, ‘viewModel’,
   function ($scope,  viewModel) {
        $scope.viewModel = viewModel;
   }]
);

[/csharp]

and here’s the MVC View

[csharp]

….

[/csharp]

Did you like this post? Then