【发布时间】:2018-10-14 05:12:23
【问题描述】:
我继承了一个混合使用 AngularJS 和 JQuery 的项目。我目前遇到动态加载的md-switch 指令在动态加载时不显示的问题。请参阅以下内容:
在我看来,我有
...
<md-switch class="md-primary md-switch-custom-margin" aria-label="Done Switch" ng-model="done"
ng-change="markDone($event, @Newtonsoft.Json.JsonConvert.SerializeObject(!Model.Done))" />
...
在第一页加载时,这个控件显示得很好。但是,在单击按钮时,我会通过 ajax 为 md-switch 所在的容器检索一个新的局部视图,如下所示:
$.ajax({
url: "../../MyController/GetPartial",
type: "GET",
dataType: "html"
}).done(function (response) {
$("#body-container").html(response);
var angularScope = angular.element("div[ng-controller='MyAngularController'").scope();
//have tried both of the following
//angularScope.$apply();
})
当部分视图被加载到页面中时,我在页面上的所有md-switchs 都不可见,尽管它们确实出现在 DOM 上并且似乎与任何操作发生之前的格式相同。
在查看了许多帖子之后,我仍然不确定我在这里缺少什么。感谢所有帮助。
【问题讨论】:
标签: .net angularjs asp.net-mvc razorengine dynamic-content