1

I was trying to use Angular in my MVC app.

Problem shows in my cshtml file:

@model List<MyProject.Models.School>
...
<tbody data-ng-init="schools = @Model">
...
<tr ng-repeat="school in schools" ng-click="selectRow(school.Id)" ng-class="{selected: school.Id == selectedIndex}">
<td> ... </td>
</tr>

But is doesn't show any rows. What am I doind wrong?

  • Why mix the angular with Razor. Use just angular insted.. – BAD_SEED Jul 11 '15 at 16:45
  • Mostly because Im not familiar with JS or Angular at all... I want to avoid it as much as possible, but I need to use ANgular here – Vardens Archangel Jul 11 '15 at 16:47
  • this won't work. if you want to iterate through server variables for rendering, razor has syntax for that. if you want to iterate through JavaScript variables, then that's where angular comes in. if you want angular to use ng-repeat, the variable must be in JavaScript. – Claies Jul 11 '15 at 19:28

1 Answers1

0

You will need to serilize your @Model to Json and pass it into the angular controller as angular has no idea what @Model contains.

How can I pass @Model to Angular ng-init

Community
  • 1
  • 1
bechbd
  • 6,206
  • 3
  • 28
  • 47