I'm new to Angular and relatively new to ASP.NET MVC. I've successfully managed to pass my server model to my AngularJS controller. However, I want to be able to edit my model before passing it to the AngularJS controller.
How would I go about to achieve this? Any help is greatly appreciated!
My view:
...
@if (Model != null)
{
<table class="table">
@for (var index = 0; index < Model.Fields.Count; index++)
{
<tr>
<td>@Html.DisplayTextFor(m => Model.Fields[index].Title)</td>
<td>@Html.EditorFor(m => Model.Fields[index].Value)</td>
</tr>
}
</table>
}
...
<form class="form-horizontal" role="form" ng-submit="posta(@System.Web.Helpers.Json.Encode(Model))">
<div>
<ul>
<li ng-repeat="article in articles">
{{ article.Article.itemNumber | uppercase }} - {{ article.Article.itemDescription | lowercase }}
</li>
</ul>
</div>
<div class="form-group">
<div style="padding-left:110px">
<input type="submit" value="OK" class="btn btn-primary" />
</div>
</div>
</form>
Controller:
var myApp = angular.module("ArticleApp", []);
myApp.controller("articleController", function ($scope) {
$scope.articles = [
{
Article: {
itemNumber: '1234',
itemDescription: 'Test'
}
},
{
Article: {
itemNumber: '5678',
itemDescription: 'Test2'
}
}
];
$scope.addRow = function () {
$scope.articles.push({
Article: {
itemNumber: '2222',
itemDescription: 'asdasd'
}
});
};
$scope.posta = function (model) { //Model does not contain changes :(
var m = $scope.articles;
}