2017-04-10 109 views
1
我使用ngResource與HTTP調用其他web服務,我爲渣滓製成

,我得到這個錯誤http://errors.angularjs.org/1.4.8/$injector/modulerr?p0=myApp&p1=Error%3A%2…0yc%20(http%3A%2F%2Flocalhost%3A8088%2Fangular%2Fangular.min.js%3A20%3A274)ngResource未能加載

我把角的js腳本引用正常,但它不工作 這是我的代碼:

var app = angular.module('myApp', ['ngResource']); 
 

 
app.controller('StadeController', ['$scope', '$resource',function($scope,$resource) { 
 
    
 
    function fetchAllStades(){ 
 
     $scope.stades = $resource('http://localhost:8088/stades' 
 
     ).query(function(data){return data;}); 
 
    }; 
 
    fetchAllStades(); 
 
    
 
    $scope.refresh = function(){ 
 
    \t fetchAllStades(); 
 
    }; 
 
    
 
    $scope.create = function(){ 
 
    \t Stade = $resource(
 
    \t \t  "http://localhost:8088/stades", 
 
    \t \t  {}, 
 
    \t \t  {save: {method:'POST',isArray:false}} 
 
    \t); 
 
    \t 
 
    \t var stade = {}; 
 
\t \t 
 
    \t stade.id = $scope.stadeForm.id; 
 
    \t stade.name = $scope.stadeForm.description; 
 
    \t stade.phoneNo = $scope.stadeForm.checked; 
 
\t \t 
 
\t \t $scope.Message = Stade.save(stade); 
 
\t \t \t \t 
 
\t \t $scope.stadeForm.id = ""; 
 
\t \t $scope.stadeForm.description=""; 
 
\t \t $scope.stadeForm.checked=""; 
 
    }; 
 
    
 
    $scope.deleteRec = function(){ 
 
    \t Stade = $resource(
 
    \t \t  "http://localhost:8088/stades/:id", 
 
    \t \t  {}, 
 
    \t \t  {save: {method:'DELETE', params: {id: '@id'}}} 
 
    \t); 
 
    \t 
 
\t \t \t 
 
\t \t Stade.delete({id: $scope.stadeForm.id}).then(function successCallback(response) { 
 
\t \t \t $scope.Message = response; 
 
\t \t }, function errorCallback(response) { 
 
\t \t  
 
\t \t }); 
 
\t \t \t \t 
 
\t \t $scope.stadeForm.id = ""; 
 
\t \t $scope.stadeForm.description=""; 
 
\t \t $scope.stadeForm.checked=""; 
 
    }; 
 
    
 
    
 
    $scope.update = function(){ 
 
    \t \t 
 
    \t Stade = $resource(
 
    \t \t  "http://localhost:8088/stades/:id", 
 
    \t \t  {}, 
 
    \t \t  {save: {method:'PUT', params: {id: '@id'}}} 
 
    \t); 
 
    \t 
 
\t \t var stade = {}; 
 
\t \t 
 
\t \t stade.id = $scope.stadeForm.id; 
 
\t \t stade.description = $scope.stadeForm.description; 
 
\t \t stade.checked = $scope.stadeForm.checked; 
 
\t \t 
 
\t \t $scope.Message = Stade.save({id: $scope.stadeForm.id}, stade); 
 
\t \t \t \t 
 
\t \t $scope.stadeForm.id = ""; 
 
\t \t $scope.stadeForm.description=""; 
 
\t \t $scope.stadeForm.checked=""; 
 
    }; 
 
    
 
}]);
<!DOCTYPE html> 
 
<html lang="en"> 
 
<body ng-app="myApp"> 
 
<div ng-controller="StadeController"> 
 
\t <form name="stadeForm" > 
 
\t 
 
\t <table class="table stripped"> 
 
\t  <thead><tr><th>ID </th> <th>checked</th> <th>description</th></tr></thead> 
 
\t  <tbody><tr ng-repeat="row in stades"> 
 
\t   <td><span ng-bind="row.id"></span></td> 
 
\t   <td><span ng-bind="row.description"></span></td> 
 
\t   <td><span ng-bind="row.checked"></span></td> 
 
\t   <td> 
 
\t \t </tr> \t </tbody> 
 
\t </table> 
 
\t <p class="bg-info info-msg" id="info1">{{Message}}</p> 
 
\t <div class="form-group" > 
 
     <label class=blue_font>description</label> 
 
     <input class=form-control type="text" id="description" ng-model="stadeForm.description" placeholder="description"> 
 
    </div> 
 
    
 
    <div class="form-group" > 
 
     <label class=blue_font>checked</label> 
 
     <input class=form-control type="text" id="checked" ng-model="stadeForm.checked" placeholder="checked"> 
 
    </div> 
 

 
    
 
<div class="btn-wrapper"> 
 
    <div class="row-gutter-5"> 
 
    <div class="col-md-4 col-xs-6 col-sm-6"> 
 
     <button class="btn btn_blue" type="button" data-ng-click="create()" id="Create" >Create</button> 
 
    </div> 
 
    <div class="col-md-4 col-xs-6 col-sm-6"> 
 
     <button class="btn btn_blue" type="button" data-ng-click="refresh()" id="refresh">Refresh</button> 
 
    </div> 
 
    </div> 
 
</div> 
 
\t 
 
\t <div class="form-group" > 
 
     <label class=blue_font>ID</label> 
 
     <input class=form-control type="text" id="ID" ng-model="stadeForm.id" placeholder="ID"> 
 
    </div>  
 
\t <div class="btn-wrapper"> 
 
    <div class="row-gutter-5"> 
 
    <div class="col-md-4 col-xs-6 col-sm-6"> 
 
     <button class="btn btn_blue" type="button" data-ng-click="deleteRec()" id="Delete" >Delete</button> 
 
    </div> 
 
    <div class="col-md-4 col-xs-6 col-sm-6"> 
 
     <button class="btn btn_blue" type="button" data-ng-click="update()" id="Update">Update</button> 
 
    </div> 
 
    </div> 
 
</div>  
 
\t  
 
\t </form> 
 
\t </div> 
 
\t <script src="angular/angular.min.js"></script> 
 
\t <script src="angular/angular-resource.min.js"></script> 
 
\t <script src=app/app.js"></script> 
 
\t <link rel="stylesheet" href="bootsrap/style.css"> \t 
 
\t <link rel="stylesheet" href="bootsrap/theme-default.css"> 
 
\t <link rel="stylesheet" href="bootsrap/theme-blue.css"> 
 
\t <link rel="stylesheet" href="bootsrap/bootstrap.min.css"> 
 
\t <link rel="stylesheet" href="bootsrap/custom.css"> 
 
</body> 
 
</html>
我不知道爲什麼它不工作,我看到有一個像我的問題,以前的職位,但沒有奏效

+0

使用非精縮的角度和使用控制檯 – harishr

+0

我這樣做,HTML鏈接找出確切的錯誤,但它沒有幫助那麼多 –

+0

我加入2腳本標記以供reference.now檢查您的api。另請參閱控制檯中是否有任何錯誤(通過按F12) –

回答

0

錯誤。打開「不見了。

應該<script src="app/app.js"></script>

<!DOCTYPE html> 
<html lang="en"> 
<body ng-app="myApp"> 
<div ng-controller="StadeController"> 
    <form name="stadeForm" > 

    <table class="table stripped"> 
      <thead><tr><th>ID </th> <th>checked</th> <th>description</th></tr></thead> 
      <tbody><tr ng-repeat="row in stades"> 
      <td><span ng-bind="row.id"></span></td> 
      <td><span ng-bind="row.description"></span></td> 
      <td><span ng-bind="row.checked"></span></td> 
      <td> 
      </tr> </tbody> 
    </table> 
    <p class="bg-info info-msg" id="info1">{{Message}}</p> 
    <div class="form-group" > 
     <label class=blue_font>description</label> 
     <input class=form-control type="text" id="description" ng-model="stadeForm.description" placeholder="description"> 
    </div> 

    <div class="form-group" > 
     <label class=blue_font>checked</label> 
     <input class=form-control type="text" id="checked" ng-model="stadeForm.checked" placeholder="checked"> 
    </div> 


<div class="btn-wrapper"> 
    <div class="row-gutter-5"> 
    <div class="col-md-4 col-xs-6 col-sm-6"> 
     <button class="btn btn_blue" type="button" data-ng-click="create()" id="Create" >Create</button> 
    </div> 
    <div class="col-md-4 col-xs-6 col-sm-6"> 
     <button class="btn btn_blue" type="button" data-ng-click="refresh()" id="refresh">Refresh</button> 
    </div> 
    </div> 
</div> 

    <div class="form-group" > 
     <label class=blue_font>ID</label> 
     <input class=form-control type="text" id="ID" ng-model="stadeForm.id" placeholder="ID"> 
    </div>  
    <div class="btn-wrapper"> 
    <div class="row-gutter-5"> 
    <div class="col-md-4 col-xs-6 col-sm-6"> 
     <button class="btn btn_blue" type="button" data-ng-click="deleteRec()" id="Delete" >Delete</button> 
    </div> 
    <div class="col-md-4 col-xs-6 col-sm-6"> 
     <button class="btn btn_blue" type="button" data-ng-click="update()" id="Update">Update</button> 
    </div> 
    </div> 
</div>  

    </form> 
    </div> 
    <script src="angular/angular.min.js"></script> 
    <script src="angular/angular-resource.min.js"></script> 
    <script src="app/app.js"></script> 
    <link rel="stylesheet" href="bootsrap/style.css"> 
    <link rel="stylesheet" href="bootsrap/theme-default.css"> 
    <link rel="stylesheet" href="bootsrap/theme-blue.css"> 
    <link rel="stylesheet" href="bootsrap/bootstrap.min.css"> 
    <link rel="stylesheet" href="bootsrap/custom.css"> 
</body> 
</html> 
+0

非常感謝你!我怎麼沒有看到xD –

+0

錯誤消失了 –

0

var app = angular.module('myApp', ['ngResource']); 
 

 
app.controller('StadeController', ['$scope', '$resource',function($scope,$resource) { 
 
    
 
    function fetchAllStades(){ 
 
     $scope.stades = $resource('http://localhost:8088/stades' 
 
     ).query(function(data){return data;}); 
 
    }; 
 
    fetchAllStades(); 
 
    
 
    $scope.refresh = function(){ 
 
    \t fetchAllStades(); 
 
    }; 
 
    
 
    $scope.create = function(){ 
 
    \t Stade = $resource(
 
    \t \t  "http://localhost:8088/stades", 
 
    \t \t  {}, 
 
    \t \t  {save: {method:'POST',isArray:false}} 
 
    \t); 
 
    \t 
 
    \t var stade = {}; 
 
\t \t 
 
    \t stade.id = $scope.stadeForm.id; 
 
    \t stade.name = $scope.stadeForm.description; 
 
    \t stade.phoneNo = $scope.stadeForm.checked; 
 
\t \t 
 
\t \t $scope.Message = Stade.save(stade); 
 
\t \t \t \t 
 
\t \t $scope.stadeForm.id = ""; 
 
\t \t $scope.stadeForm.description=""; 
 
\t \t $scope.stadeForm.checked=""; 
 
    }; 
 
    
 
    $scope.deleteRec = function(){ 
 
    \t Stade = $resource(
 
    \t \t  "http://localhost:8088/stades/:id", 
 
    \t \t  {}, 
 
    \t \t  {save: {method:'DELETE', params: {id: '@id'}}} 
 
    \t); 
 
    \t 
 
\t \t \t 
 
\t \t Stade.delete({id: $scope.stadeForm.id}).then(function successCallback(response) { 
 
\t \t \t $scope.Message = response; 
 
\t \t }, function errorCallback(response) { 
 
\t \t  
 
\t \t }); 
 
\t \t \t \t 
 
\t \t $scope.stadeForm.id = ""; 
 
\t \t $scope.stadeForm.description=""; 
 
\t \t $scope.stadeForm.checked=""; 
 
    }; 
 
    
 
    
 
    $scope.update = function(){ 
 
    \t \t 
 
    \t Stade = $resource(
 
    \t \t  "http://localhost:8088/stades/:id", 
 
    \t \t  {}, 
 
    \t \t  {save: {method:'PUT', params: {id: '@id'}}} 
 
    \t); 
 
    \t 
 
\t \t var stade = {}; 
 
\t \t 
 
\t \t stade.id = $scope.stadeForm.id; 
 
\t \t stade.description = $scope.stadeForm.description; 
 
\t \t stade.checked = $scope.stadeForm.checked; 
 
\t \t 
 
\t \t $scope.Message = Stade.save({id: $scope.stadeForm.id}, stade); 
 
\t \t \t \t 
 
\t \t $scope.stadeForm.id = ""; 
 
\t \t $scope.stadeForm.description=""; 
 
\t \t $scope.stadeForm.checked=""; 
 
    }; 
 
    
 
}]);
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> 
 
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.7/angular-resource.min.js"></script> 
 

 
<!DOCTYPE html> 
 
<html lang="en"> 
 
<body ng-app="myApp"> 
 
<div ng-controller="StadeController"> 
 
\t <form name="stadeForm" > 
 
\t 
 
\t <table class="table stripped"> 
 
\t  <thead><tr><th>ID </th> <th>checked</th> <th>description</th></tr></thead> 
 
\t  <tbody><tr ng-repeat="row in stades"> 
 
\t   <td><span ng-bind="row.id"></span></td> 
 
\t   <td><span ng-bind="row.description"></span></td> 
 
\t   <td><span ng-bind="row.checked"></span></td> 
 
\t   <td> 
 
\t \t </tr> \t </tbody> 
 
\t </table> 
 
\t <p class="bg-info info-msg" id="info1">{{Message}}</p> 
 
\t <div class="form-group" > 
 
     <label class=blue_font>description</label> 
 
     <input class=form-control type="text" id="description" ng-model="stadeForm.description" placeholder="description"> 
 
    </div> 
 
    
 
    <div class="form-group" > 
 
     <label class=blue_font>checked</label> 
 
     <input class=form-control type="text" id="checked" ng-model="stadeForm.checked" placeholder="checked"> 
 
    </div> 
 

 
    
 
<div class="btn-wrapper"> 
 
    <div class="row-gutter-5"> 
 
    <div class="col-md-4 col-xs-6 col-sm-6"> 
 
     <button class="btn btn_blue" type="button" data-ng-click="create()" id="Create" >Create</button> 
 
    </div> 
 
    <div class="col-md-4 col-xs-6 col-sm-6"> 
 
     <button class="btn btn_blue" type="button" data-ng-click="refresh()" id="refresh">Refresh</button> 
 
    </div> 
 
    </div> 
 
</div> 
 
\t 
 
\t <div class="form-group" > 
 
     <label class=blue_font>ID</label> 
 
     <input class=form-control type="text" id="ID" ng-model="stadeForm.id" placeholder="ID"> 
 
    </div>  
 
\t <div class="btn-wrapper"> 
 
    <div class="row-gutter-5"> 
 
    <div class="col-md-4 col-xs-6 col-sm-6"> 
 
     <button class="btn btn_blue" type="button" data-ng-click="deleteRec()" id="Delete" >Delete</button> 
 
    </div> 
 
    <div class="col-md-4 col-xs-6 col-sm-6"> 
 
     <button class="btn btn_blue" type="button" data-ng-click="update()" id="Update">Update</button> 
 
    </div> 
 
    </div> 
 
</div>  
 
\t  
 
\t </form> 
 
\t </div> 
 
\t <script src="angular/angular.min.js"></script> 
 
\t <script src="angular/angular-resource.min.js"></script> 
 
\t <script src=app/app.js"></script> 
 
\t <link rel="stylesheet" href="bootsrap/style.css"> \t 
 
\t <link rel="stylesheet" href="bootsrap/theme-default.css"> 
 
\t <link rel="stylesheet" href="bootsrap/theme-blue.css"> 
 
\t <link rel="stylesheet" href="bootsrap/bootstrap.min.css"> 
 
\t <link rel="stylesheet" href="bootsrap/custom.css"> 
 
</body> 
 
</html>
就行 <script src=app/app.js"></script>

+0

我已經引用底部的angular.min.js和angular-resource.min.js –