错误:[NG:AREQ] http://errors.angularjs.org/1.3.8/ng/areq?p0=homeIndexController&p1=not功能,得到了不确定 [英] Error: [ng:areq] http://errors.angularjs.org/1.3.8/ng/areq?p0=homeIndexController&p1=not a function, got undefined

查看:1449
本文介绍了错误:[NG:AREQ] http://errors.angularjs.org/1.3.8/ng/areq?p0=homeIndexController&p1=not功能,得到了不确定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请不要将此标记为重复。我已经看到了这个错误张贴在堆栈溢出很多重复。但我的情况,我有最简单的贴在那里的应用程序,但得到了同样的错误。

Please do not mark this as a duplicate. I have seen many duplicates of this error posted in stack overflow. But my case is, I have the simplest of the applications posted there, but getting the same error.

我想学角度JS。下面是我_Layout.chtml样子。

I am trying to learn Angular JS. Below is my _Layout.chtml looks like.

<!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是如下:

My Index.chtml is as below:

@{
    ViewBag.Title = "Home Page";
}
@section PageScripts
{
    <script src="~/js/home-index.js"></script>
}
<div data-ng-controller="homeIndexController">
    <div>Test</div>
</div>

我家index.js文件如下:

My home-index.js file is as below:

//home-index.js
if (window.console) { console.log("In home-index"); }
function homeIndexController() {
    alert("Inside the home index controller");
}

另外,我看到的替换数据-NG-应用程序和数据-NG-控制器
   NG-应用和NG-控制器
作为我的一些朋友建议不解决问题。

Also, I see that replacing data-ng-app and data-ng-controller with ng-app and ng-controller do not fix the problem as some of my friends suggested.

在控制台中,我看到了在家里指数被打印出来,但功能是不确定的。我检查了函数名和与控制器声明相匹配。

In the Console, I see the In home-index is printed, but the function is undefined. I checked the function Name and matched with the controller declaration.

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

任何建议都欢迎。

Any suggestions are welcome.

推荐答案

我觉得先不要张贴答案。然后,我认为这将是伟大的新手喜欢我知道,很多最简单的例子角度讲述使用在全球范围内全局控制器声明。关于这个技术细节可以在这里找到 。鸭preciate PSL的努力很快指点我到正确的地方。

I thought first not to post an answer. Then I thought it would be great for newbies like me to know that many of the simplest angular examples tell about using global controller declaration on the global scope. The technical details about this can be found here. Appreciate PSL's effort to quickly pointing me to the right place.

我公司提供的应用程序,以NG-应用

I provided "app" to ng-app

<html lang="en" data-ng-app="app">

和改变我下面的JavaScript调用:

and changed my javascript call as below:

angular.module('app', []).controller('homeIndexController', function homeIndexController($scope) {
    alert("Inside the home index controller");
});

这篇关于错误:[NG:AREQ] http://errors.angularjs.org/1.3.8/ng/areq?p0=homeIndexController&amp;p1=not功能,得到了不确定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆