角应用程序名称没有确定 [英] Angular application name not identified

查看:120
本文介绍了角应用程序名称没有确定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用下面的示例code定义DB访问工厂:

I'm trying to define a factory for DB access using the following sample code:

    MyApp.service("DB_Services", [ "$http" , function($http) {

        DB_Services.Get_Data_from_DB_Internal = function (p_Request) {

            var http = new XMLHttpRequest();
            var url  = "http://localhost/servlet/Test_ui";
            var params = "data=" + p_Request ;
            http.open("POST", url, true);

            //Send the proper header information along with the request
            http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");

            if(http.readyState == 4 && http.status == 200) {
                    return http.responseText ;
                }
        }
        http.send(params);    


        return DB_Services ;
    }]);

我要补充一点,这块code被部署在与在中所列的单独文件; SCRIPT SRC = ...> 在入境中的index.html。

I should add that this piece of code is deployed in a separate file which is listed in a <script src=...> entry within the index.html.

在加载(以及任何使用它之前!),我得到以下错误(Chorme的控制台):未捕获的Ref​​erenceError:MyApp的没有定义

Upon loading (and before any use of it!), I get the following error (Chorme's console): Uncaught ReferenceError: MyApp is not defined.

当然,MyApp的是贯穿所有的控制器使用同样的名字,所以不存在拼写错误。

Of course, MyApp is the very same name used throughout all controllers, so there is no spelling error.

此外,如果我改变MyApp的别的东西,说:测试名,我得到了同样的错误,只是这一次没有定义什么是测试名。

Moreover, if I change "MyApp" to something else, say, "TestName", I get the same error except that this time what is not defined is TestName.

想不通的语法错误是什么。

Cannot figure out what the syntax error is.

任何想法将AP preciated。

Any idea will be appreciated.

推荐答案

这样的回答是基于你是白手创业的角度应用(如 angular.module('对myApp')的假设)在一个单独的&LT;脚本&GT; 文件在您的index.html

This answer is based on the assumption you are bootstrapping your angular app (e.g. angular.module('myApp')) in a separate <script> file in your index.html

您需要确保您的初始角度设置code之前出现其它任何角度&LT;脚本方式&gt; 取值

You need to ensure that your initial angular setup code appears before any other angular <script>s.

<head>
    .....
    <script>
         var myApp = angular.module('myApp', [])
    </script>

    <script src="otherNg.js">
    <script src="anotherNg.js">

一定要引用您的模块中的其他&LT;脚本&GT; 文件正确

为了正确地添加额外的结构到你的对myApp 模块,您需要确保正确地访问它。因为它是在另一个文件中定义的,你需要使用下面的语法来访问它:

be sure to reference your module in other <script> files properly

In order to properly add additional constructs to your myApp module, you need to be sure to access it properly. Since it was defined in another file, you need to use the following syntax to gain access to it:

 var myApp = angular.module('myApp')
 .service("DB_Services", [ .... ])

请注意,这code不包括数组的第二个参数...这是因为这是的的getter 的语法获取已经定义的模块。

Note that this code doesn't include the 2nd parameter of the array... this is because this is getter syntax for getting already defined modules.

这篇关于角应用程序名称没有确定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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