このような _Layout ページに ng-controller があります。
<div ng-controller="LayoutController">
left content....
@RenderBody
right content..
そして、ajaxを使用したレイアウトで角度モジュールを使用します(その部分は機能します)
<script type="text/javascript">
var module_ = angular.module("myapp", []);
var controller_ = module_.controller("layoutController", function ($scope) {
$.ajax({
type: "POST",
url: "Home/GetMenu",
success: function (result) {
$.each(result, function (i, ix) {
result[i].ID = i + 1;
});
$scope.TopCharactersModel = result;
$scope.$apply();
},
complete: function () {
}
})
次に、このレイアウト ページから派生した Index.html 内で別の Ng-Controller を使用したいと考えています。Javascript コードはこの側では機能せず、chrome デバッガーはこのエラーを表示します 。警告: 角度を複数回ロードしようとしました。
<div ng-controller="IndexController">
<div class="panel-group" id="accordion" ng-repeat="arr_ in newsArr">
</div>
</div>
<script>
var module = angular.module("myapp", []);
var myController1 = module_.controller("IndexController", function ($scope) {
$.ajax({
url: "Home/GetNews",
type: "POST",
success: function (result) {
$scope.newsArr = result;
// $scope.$digest();
$scope.$apply()
},
complete: function () {
}
});
});
</script>