請不要將其標記爲重複項。我發現這個錯誤在堆棧溢出中發佈了很多重複。但我的情況是,我有最簡單的應用程序發佈在那裏,但獲得相同的錯誤。錯誤:[ng:areq] http://errors.angularjs.org/1.3.8/ng/areq?p0=homeIndexController&p1=不是函數,得到undefined
我想學習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>
我家index.js文件如下:
//home-index.js
if (window.console) { console.log("In home-index"); }
function homeIndexController() {
alert("Inside the home index controller");
}
另外,我看到替換數據-NG -app和數據ng控制器 ng-app和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
任何建議都歡迎。
'請不要將此標記爲重複。我發現這個錯誤在堆棧溢出中發生了很多重複。「對不起,這是重複的。請閱讀答案,這正是你的問題。 – PSL
@PSL,謝謝。你達人!!! – user007