我尝试使用下面的示例代码来定义DB访问一家工厂:
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 ;
}]);
我要补充的是这段代码被部署在其以列出一个单独的文件<script src=...>
中的index.html内条目。
在加载时(以及任何使用它之前!),我得到以下错误(Chorme的控制台):未捕获的ReferenceError:未定义MyApp的。
当然,MyApp的是在所有的控制器使用了同样的名字,所以不存在拼写错误。
此外,如果我改变“MyApp的”别的东西,说:“测试名”,我得到了同样的错误,只是这次没有定义什么是测试名称。
想不通的语法错误是什么。
任何想法将不胜感激。