我正在遵循以下指南:http://blog.mariusschulz.com/2014/03/25/bootstrapping-angularjs-applications-with-server-side-data-from-aspnet-mvc
这段代码对我来说很好,我可以看到@Html.Raw(模型)的输出,它是有效的JSON
<script>
angular.module("hobbitModule").value("companionship", @Html.Raw(Model));
</script>但是,当我运行这段代码时
var module = angular.module("hobbitModule");
module.controller("CompanionshipController", function($scope, companionship) {
$scope.companions = companionship;
});“陪伴”变量总是没有定义。这是我的版本
<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;
}]);发布于 2014-06-23 23:55:04
您应该在控制器中添加$scope旁边的“友谊”注释。
ng.module('myApp.controllers')
.controller('AccountCtrl', ['$scope', 'companionship', function ($scope, companionship) {
$scope.companions = companionship;
}]);https://stackoverflow.com/questions/24376313
复制相似问题