Sign up ×
Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them, it only takes a minute:

I'm trying to access my asp.net MVC model from angularjs. I can convert the model to a javascript object using var model = @Html.Raw(Json.Encode(Model)); this works fine -I can access the object from the console in chrome.

Next I try to create a UL wit ng-repeat -this doesn't work. The UL does not appear on the page and there are no errors in the console. Can anyone tell me what I might be doing wrong?

<script type="text/javascript" src="/Scripts/angular.min.js"> </script>
<script type="text/javascript" src="/Scripts/app.js"> </script>




<h2>Heading</h2>


    @using (Html.BeginForm())
{
    @Html.AntiForgeryToken()

    <div class="form-horizontal" ng-app="app" ng-controller="editUser">

        <script type="text/javascript">
            var model = @Html.Raw(Json.Encode(Model));
            var Permissions = model.Permissions;
        </script>

        <h4>UserSetting</h4>
        <hr/>
        @Html.ValidationSummary(true, "", new {@class = "text-danger"})
        @Html.HiddenFor(model => model.Id)



        <ul>
            <li ng-repeat="permission in Permissions">
                <span>{{permission.Guid}}</span>
                <p>{{permission.SatelliteAccount}}</p>
            </li>
        </ul>

And my app.js:

var app= angular.module('app', []);

app.controller('editUser', function ($scope) {



});
share|improve this question

1 Answer 1

ng-repeat is repeating over $scope.Permissions, which is undefined. You cannot repeat over global variables, you need to define those on the angular scope in the controller.

app.js:

var app= angular.module('app', []);

app.controller('editUser', function ($scope) {

    $scope.Permissions = Permissions;

});
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.