use*_*379 23 html javascript service controller angularjs
我收到此错误,我尝试了不同的方法,但我还没有找到任何解决方案.
这是我的代码:
services.js
angular
.module('myApp.services',[])
.service('myservice', function($resource) {
var pendings = $resource('myUrl2', {methode: 'GET', isArray:true});
var items;
var myPo='rawad al bo3bo3';
var quantity;
var barcode;
return {
getItems: function() {
items = $resource('myUrl', {methode: 'GET', isArray:true});
Run Code Online (Sandbox Code Playgroud)
这是我的控制器:
angular
.module('myApp.controllers', [])
.controller('ReceiveCtrl', ['$scope','myservice', function ($scope,myservice) {
Run Code Online (Sandbox Code Playgroud)
HTML:
<html lang="en" ng-app="myApp">
<head>
<meta charset="utf-8">
<title>My AngularJS App</title>
<!-- <link rel="stylesheet" href="lib/primeUI/prime-ui-0.9.5.css"> -->
</head>
<body>
<ul class="menu">
<li><a href="#/Receive">view1</a></li>
<li><a href="#/Pending">view2</a></li>
</ul>
<div ng-view></div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
在控制器中,我无法访问来自我的服务的变量...因此警报消息将不起作用,我收到此错误
Error: Unknown provider: $resourceProvider <- $resource <- myservice
Run Code Online (Sandbox Code Playgroud)
lua*_*sus 60
您必须包含angular-resource.js文件和加载ngResource模块:angular.module('app', ['ngResource'])
有关更多详细信息,请查看$resource服务文档中的"安装"部分:http://docs.angularjs.org/api/ngResource.$ resource
小智 14
服务模块还需要资源.
angular.module('myApp.services',[])
Run Code Online (Sandbox Code Playgroud)
应该
angular.module('myApp.services',['ngResource'])
Run Code Online (Sandbox Code Playgroud)
并且控制器需要知道您的服务模块
angular.module('myApp.controllers', [])
Run Code Online (Sandbox Code Playgroud)
至
angular.module('myApp.controllers', ['myApp.services','myApp.filters', 'myApp.directives'])
Run Code Online (Sandbox Code Playgroud)
而且从技术上来说,你的motherModule不需要myApp.services只需要myApp.controllers
angular.module('myApp', ['myApp.services','myApp.filters', 'myApp.directives' 'myApp.controllers']).
Run Code Online (Sandbox Code Playgroud)
至
angular.module('myApp', ['myApp.controllers']).
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
20932 次 |
| 最近记录: |