2016-12-09 8 views
0

ファイル構造:

enter image description here

がapp.js

(function() { 
    "use strict"; 

    var app = angular.module("app", ["common.services", "ngRoute", "ngResource"]) 

    app.config(function ($routeProvider) { 
     $routeProvider 
     // route for the home page 
     //.when('/', { 
     // controller: 'mainController', 
     // templateUrl: 'app/linkPages/home.html' 
     //}) 

     // route for the about page 
     //.when('/about', { 
     // controller: 'aboutController', 
     // templateUrl: 'app/linkPages/about.html' 
     //}) 

     // route for the contact page 
     //.when('/contact', { 
     // controller: 'contactController', 
     // templateUrl: 'app/linkPages/contact.html' 
     //}) 

     .when('/', { 
      controller: 'AgencyListCtrl', 
      templateUrl: 'app/agencies/agencyListView.html' 
     }) 

     //.when('/agencyEditView', { 
     // controller: 'AgencyEditCtrl', 
     // templateUrl: 'app/agencies/agencyEditView.html' 
     //}); 

    }); 

    // create the controller and inject Angular's $scope 
    app.controller('mainController', function ($scope) { 
     // create a message to display in our view 
     $scope.message = 'This is the Main controller page'; 
    }); 

    app.controller('aboutController', function ($scope) { 
     $scope.message = 'This is the about controller page'; 
    }); 

    app.controller('contactController', function ($scope) { 
     $scope.message = 'This is the contact controller page'; 
    }); 

}()); 

common.services.js

(function() { 
    "use strict"; 

    angular 
     .module("common.services", 
        ["ngResource"])//common.services 

     .constant("appSettings", 
     { 
      serverPath: "http://localhost:53403/" // will replace production server url 
     }); 
}()); 

agencyResource.js

(function() { 

    "use strict"; 

    angular.module("app")//common.services 
     .factory("agencyResource" 
       ["ngResource", "$resource", 
       "appSettings", 
        agencyResource]) 

    function agencyResource($resource, appSettings) { 
     return $resource(appSettings.serverPath + "/api/v1/agencies/:id", null, 
      { 
       'update': { method: 'PUT' }, 
      }); 
    } 

}()); 

agencyListCtrl.js

(function() { 

    "use strict"; 

    angular 
     .module("app") 
     .controller("AgencyListCtrl", 
        ["agencyResource", 
        AgencyListCtrl]); 

    function AgencyListCtrl(agencyResource) { 
     var vm = this; 

     //agencyResource.query({ $filter: "contains(Abbr,'IOT')" }, 
     // function (data) { 
     //  vm.agencies = data; 

     //  console.log(result); 
      //}) 

     agencyResource.query({}, 
      function (data) { 
       vm.agencies = data; 

     console.log(result); 
    }) 

} 
}()); 

ERROR:

HTML1300: Navigation occurred. index.html Error: [$injector:unpr] Unknown provider: agencyResourceProvider <- agencyResource <- AgencyListCtrl http://errors.angularjs.org/1.5.9/ $injector/unpr?p0=agencyResourceProvider%20%3C-%20agencyResource%20%3C-%20AgencyListCtrl at Anonymous function (http://localhost:61924/Scripts/angular.js:4554:13) at getService (http://localhost:61924/Scripts/angular.js:4707:11) at Anonymous function (http://localhost:61924/Scripts/angular.js:4559:13) at getService (http://localhost:61924/Scripts/angular.js:4707:11) at injectionArgs (http://localhost:61924/Scripts/angular.js:4731:9) at instantiate (http://localhost:61924/Scripts/angular.js:4774:7) at $controller (http://localhost:61924/Scripts/angular.js:10533:7) at link (http://localhost:61924/Scripts/angular-route.js:1056:9) at Anonymous function (http://localhost:61924/Scripts/angular.js:1258:11) at invokeLinkFn (http://localhost:61924/Scripts/angular.js:10095:9)

私は天気が私は右ここですべてを注入していることを確認していませんか?どんな助けもありがとう。これは私の最初の角型アプリなので、私は少し緑色です。私は私が詳細を入力する必要がありますが、コードポストはかなり自明であると私に言っているスタックオーバーフロー。 I

+0

チェックあなたは私があなたのagencyResourceリソース宣言のビット骨董午前agencyListCtrl.js – emed

+1

前agencyResource.jsをインポートする場合。 "ngResource"、 "$ resource"、 "appSettings" 'を注入していますが、パラメータは' agencyResource($ resource、appSettings) 'です。駄目かもしれない。 –

答えて

0

答えは、agencyResource.jsファイルでngResourceを宣言していたことです。このように見えるはずです。私の悪い。

agencyResource.jsのindex.htmlで

(function() { 
 

 
    "use strict"; 
 

 
    angular.module("common.services")//common.services 
 
     .factory("agencyResource", 
 
       [ 
 
       "$resource", 
 
       "appSettings", 
 
        agencyResource 
 
       ]) 
 

 
    function agencyResource($resource, appSettings) { 
 
     return $resource(appSettings.serverPath + "/api/v1/agencies/:id", null, 
 
      { 
 
       'update': { method: 'PUT' }, 
 
      }); 
 
    } 
 

 
}());

関連する問題