请不要将此标记为重复。我在堆栈溢出中看到了许多重复的此错误。但我的情况是,我在那里发布了最简单的应用程序,但得到了同样的错误。
我正在尝试学习 Angular JS。下面是我的 _Layout.chtml 的样子。
<!DOCTYPE html>
<html lang="en" data-ng-app="">
<head>
<meta charset="utf-8">
<!-- Title here -->
<title>@ViewBag.Title - MessageBoard</title>
<!-- Description, Keywords and Author -->
<meta name="description" content="Your description">
<meta name="keywords" content="Your,Keywords">
<meta name="author" content="ResponsiveWebInc">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- Stylesheets -->
<link href="~/Content/Template/css/bootstrap.min.css" rel="stylesheet">
<link href="~/Content/Template/css/ddlevelsmenu-base.css" rel="stylesheet">
<link href="~/Content/Template/css/ddlevelsmenu-topbar.css" rel="stylesheet">
<link href="~/Content/Template/css/flexslider.css" rel="stylesheet">
<link href="~/Content/Template/css/prettyPhoto.css" rel="stylesheet">
<link href="~/Content/Template/css/font-awesome.min.css" rel="stylesheet">
<link href="~/Content/Template/css/blue.css" rel="stylesheet">
<link href="~/Content/Template/css/style.css" rel="stylesheet">
<link href="~/Content/Site.css" rel="stylesheet">
<!-- Favicon -->
<link rel="shortcut icon" href="~/Content/Template/img/favicon/favicon.png">
</head>
<body>
<div class="main">
<div class="container">
<div class="row">
@RenderBody()
</div>
</div>
</div>
<script src="~/Scripts/jquery-2.1.1.min.js"></script>
<script src="~/Scripts/angular.min.js"></script>
<script src="~/Scripts/bootstrap.min.js"></script>
<script src="~/Scripts/easing.js"></script>
<script src="~/Scripts/ddlevelsmenu.js"></script>
<script src="~/Scripts/flexslider.js"></script>
<script src="~/Scripts/jquery.prettyPhoto.js"></script>
<script src="~/Scripts/respond.min.js"></script>
<script src="~/Scripts/html5shiv.js"></script>
<script src="~/Scripts/custom.js"></script>
@RenderSection("PageScripts", required: false)
</body>
</html>
我的 Index.chtml 如下:
@{
ViewBag.Title = "Home Page";
}
@section PageScripts
{
<script src="~/js/home-index.js"></script>
}
<div data-ng-controller="homeIndexController">
<div>Test</div>
</div>
我的 home-index.js 文件如下:
//home-index.js
if (window.console) { console.log("In home-index"); }
function homeIndexController() {
alert("Inside the home index controller");
}
另外,我发现用 ng-app 和 ng-controller 替换 data-ng-app 和 data-ng-controller 并不能解决我的一些朋友建议的问题。
在控制台中,我看到 In home-index 已打印,但功能未定义。我检查了函数名称并与控制器声明匹配。
HTML1300: Navigation occurred.
File: localhost:50272
In home-index
Error: [ng:areq] http://errors.angularjs.org/1.3.8/ng/areq?p0=homeIndexController&p1=not%20a%20function%2C%20got%20undefined
at Qb (http://localhost:50272/Scripts/angular.min.js:19:411)
at sb (http://localhost:50272/Scripts/angular.min.js:20:1)
at Anonymous function (http://localhost:50272/Scripts/angular.min.js:76:95)
at Anonymous function (http://localhost:50272/Scripts/angular.min.js:57:255)
at s (http://localhost:50272/Scripts/angular.min.js:7:406)
at v (http://localhost:50272/Scripts/angular.min.js:57:124)
at g (http://localhost:50272/Scripts/angular.min.js:52:9)
at g (http://localhost:50272/Scripts/angular.min.js:52:26)
at g (http://localhost:50272/Scripts/angular.min.js:52:26)
at g (http://localhost:50272/Scripts/angular.min.js:52:26)
SEC7115: :visited and :link styles can only differ by color. Some styles were not applied to :visited.
File: localhost:50272
欢迎任何建议。