【发布时间】:2016-04-18 07:17:59
【问题描述】:
我有一个 $watch,我正在更新我的模型。但是我的模型无法更新 UI 中的绑定控件。
我的用户界面有这个
<form method="post" action="" role="form" class="form-horizontal form-group-sm">
<table ng-controller="myController" class="table table-responsive table-striped">
<tr>
<td>
<label for="moduleid" class="col-md-2">Module ID : </label>
<div class="form-group col-md-3">
<input type="text" id="moduleid" name="moduleid" ng-model="hdr.moduleid" value="" class="form-control">
</div>
</td>
</tr>
<tr>
<td>
<label for="modulename" class="col-md-2">Module Name : </label>
<div class="form-group col-md-4">
<input type="text" id="modulename" name="modulename" ng-model="hdr.modulename" value="" class="form-control">
</div>
</td>
</tr>
<tr>
<td>
<label for="status" class="col-md-2">Status : </label>
<div class="form-group col-md-4">
@Html.DropDownList("status", (List<SelectListItem>)ViewBag.StatusList, new { @class = "form-control ComboM required", @ng_model = "hdr.status", @style = "width: 240px" })
@Html.AntiForgeryToken()
</div>
</td>
</tr>
</table>
</form>
为什么无法更新我的 UI。
EDIT :也尝试了以下方法。还是没有运气。
$scope.$watch("mySelectedItems[0]", function (newVal, oldVal) {
var val;
if (newVal != oldVal) {
if (newVal == undefined && oldVal)
$scope.hdr = oldVal;
else $scope.hdr = newVal;
}
// alert($scope.hdr.modulename);
});
EDIT 2:在JS Fiddle 中工作,但在我的项目中没有。请看原文SO Question
【问题讨论】:
标签: angularjs asp.net-mvc model-view-controller