Angularjs 模块';MyApp';不可用
我在mvc项目中使用angular 我添加了以下js文件,并将其命名为MyApp.jsAngularjs 模块';MyApp';不可用,angularjs,asp.net-mvc-4,Angularjs,Asp.net Mvc 4,我在mvc项目中使用angular 我添加了以下js文件,并将其命名为MyApp.js (function () { //Create a Module var MyApp = angular.module('MyApp', ['ngRoute']); // Will use ['ng-Route'] when we will implement routing })(); 在my_Layout.cshtml上,我已将ng应用程序添加到body标记中 <body ng-app=
(function () {
//Create a Module
var MyApp = angular.module('MyApp', ['ngRoute']); // Will use ['ng-Route'] when we will implement routing
})();
在my_Layout.cshtml上,我已将ng应用程序添加到body标记中
<body ng-app="MyApp">
.....
Code
.....
</body>
然而,每次我运行程序时,我都会得到错误
错误:[$injector:nomod]模块“MyApp”不可用!您要么拼错了模块名,要么忘记加载它。如果注册模块,请确保将依赖项指定为第二个参数。
$injector/nomod?p0=MyApp
我知道我没有拼错,我读到它可能是我的脚本顺序的问题。我试过几种选择,但都没有找到问题
有人能帮我吗 您在视图中包括
MyApp.js
,而不是myu Layout.cshtml
。
尝试将其包含在与您的
相同的级别。在包含应用程序之前尝试加载应用程序,这会导致错误。当然,@Scripts.Render(“~/bundles/angular”)
部分也应该在my\u Layout.cshtml
中
我记得,如果您包含两次相同的模块,您可能会出现此错误,请确保您没有包含两次您的
MyApp
模块。我也遇到过同样的问题,在我的情况下,这只是控制器中的某个
我发现我的JSON存在编码问题。如果遇到相同的问题,请尝试清空控制器,并查看是否存在语法或编码错误我进行了更改,但仍然存在错误。我删除了MyApp.js文件并再次创建了它,现在错误消失了。非常感谢。
@Scripts.Render("~/bundles/angular")
<script src="../../Scripts/MyApp.js" type="text/javascript"></script>
<script src="~/Scripts/AngularController/BudgetAndDetails.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
$('body').on('click', '.CX span', function () {
//When Click On + sign
if ($(this).text() == '+') {
$(this).text('-');
}
else {
$(this).text('+');
}
$(this).closest('tr') // row of + sign
.next('tr') // next row of + sign
.toggle(); // if show then hide else show
});
});
</script>
<div ng-controller="BudgetAndDetails">
<table class="tableData" border="0" cellspacing="0" cellpadding="0">
<thead>
<tr>
<th></th>
<th>Budget Name</th>
<th>Year</th>
<th>Month</th>
</tr>
</thead>
<tbody ng-repeat="O in budgetdetails">
<tr ng-class-even="'even'" ng-class-odd="'odd'">
<td class="CX"><span>+</span></td>
<td>{{O.budget.BudgetName}}</td>
<td>{{O.budget.Year}}</td>
<td>{{O.budget.monthname.MonthName1}}</td>
</tr>
<tr class="sub">
<td></td>
<td colspan="5">
<table class="tableData" border="0" cellspacing="0" cellpadding="0">
<tr>
<th>Category</th>
<th>Subcateogry</th>
<th>Amount</th>
</tr>
<tr ng-repeat="a in O.budgetdetails" ng-class-even="'even'" ng-class-odd="'odd'">
<td>{{a.category.CategoryName}}</td>
<td>{{a.subcategory.SubCategoryName}}</td>
<td>{{a.Amount}</td>
</tr>
</table>
</td>
</tr>
</tbody>
</table>
</div>
bundles.Add(new ScriptBundle("~/bundles/angular").Include(
"~/Scripts/angular.js",
"~/Scripts/angular-route.js"));