如何在angularjs上提供服务
How to put a services on angularjs?
我正试图在angular js上编写一个模块,用于放置我的服务(文件:utils/productos.js),然后将其作为我的模块ventas(ventas/ventas.js)的依赖项加载,但
我得到下一个错误:
Error: [$injector:nomod] Module 'utils.producto' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.
http://errors.angularjs.org/1.3.10/$injector/nomod?p0=utils.producto angular.js:63:11
Error: [$injector:modulerr] Failed to instantiate module webui due to:
[$injector:modulerr] Failed to instantiate module utils.producto due to:
[$injector:nomod] Module 'utils.producto' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.
http://errors.angularjs.org/1.3.10/$injector/nomod?p0=utils.producto
minErr/<@http://localhost/cat-dog/web/app/js/angular.js:63:12
module/<@http://localhost/cat-dog/web/app/js/angular.js:1764:1
ensure@http://localhost/cat-dog/web/app/js/angular.js:1688:38
module@http://localhost/cat-dog/web/app/js/angular.js:1762:1
loadModules/<@http://localhost/cat-dog/web/app/js/angular.js:4094:22
forEach@http://localhost/cat-dog/web/app/js/angular.js:323:11
loadModules@http://localhost/cat-dog/web/app/js/angular.js:4078:5
loadModules/<@http://localhost/cat-dog/web/app/js/angular.js:4095:40
forEach@http://localhost/cat-dog/web/app/js/angular.js:323:11
lo
app.js
var app = angular.module('webui', ['ngRoute', 'utils.producto', 'ventas']);
main.html
<script type="text/javascript" src="ventas/ventas.js"></script>
<script type="text/javascript" src="js/app.js"></script>
<script type="text/javascript" src="utils/productos.js"></script>
ventas/ventas.js
angular.module('ventas', ['ngRoute', 'utils.producto'])
.config(['$routeProvider', function ($routeProvider) {
$routeProvider.when('/ventas', {
templateUrl: 'ventas/ventas.html',
controller: 'VentasCtrl'
});
}])
utils/producto.js
angular.module('utils.producto').factory("buscadorProductos", buscadorProductos).factory("autocompProductos", autocompProductos);
function buscadorProductos($http) {
..
像angular.module('utils.producto',[])
一样,首先将服务定义为模块
代码
angular.module('utils.producto',[]).factory("buscadorProductos", buscadorProductos).factory("autocompProductos", autocompProductos);
function buscadorProductos($http) {
相关文章:
- AngularJS-需要在index.html页面中访问来自服务的数据
- 在AngularJS服务中使用$http回调
- 使用服务(AngularJS)在控制器之间共享数据
- 从AngularJS中的另一个文件中的控制器访问服务
- AngularJS 1.5.x服务未正确绑定,并且未在控制器中更新
- AngularJS:使用维基百科API的web服务
- 如何在angularjs上提供服务
- AngularJS中介服务中的解约
- 使用角度模态服务(AngularJS)自定义模态
- 从服务 AngularJS + TypeScript 调用指令
- 无法使用服务AngularJS - “无法读取未定义的属性'原型'”
- 将 localStorage 值传递到服务 angularjs 中
- $broadcast不是从服务(AngularJS)触发的
- 在服务angularjs中的函数中使用$scope
- 配置依赖于另一个服务angularjs的服务
- 在服务AngularJS中存储变量
- forEach内部提供商服务AngularJS
- 从控制器传递多个参数到服务angularjs
- 无法从工厂向服务angularJS返回值
- 只保存服务器上更改的对象:Restful服务+angularjs