asp.net mvc - Set angular model from MVC model -
asp.net mvc - Set angular model from MVC model -
i next guide: http://blog.mariusschulz.com/2014/03/25/bootstrapping-angularjs-applications-with-server-side-data-from-aspnet-mvc
this code works fine me, i.e. can see output of @html.raw(model) , valid json
<script> angular.module("hobbitmodule").value("companionship", @html.raw(model)); </script>
however when run code
var module = angular.module("hobbitmodule"); module.controller("companionshipcontroller", function($scope, companionship) { $scope.companions = companionship; });
the "companionship" variable undefined. here version
<script type="text/javascript"> angular.module("myapp.controllers").value("companionship",@html.raw(jsonconvert.serializeobject(model))); </script> ng.module('myapp.controllers') .controller('accountctrl', ['$scope', function ($scope, companionship) { $scope.companions = companionship; }]);
you should adding 'companionship' annotation next $scope controller
ng.module('myapp.controllers') .controller('accountctrl', ['$scope', 'companionship', function ($scope, companionship) { $scope.companions = companionship; }]);
asp.net-mvc angularjs
Comments
Post a Comment