휴식 API를 호출 한 후 탐색 링크 중 하나를 클릭 할 때 업데이트해야하는 ngView 지시문이있는 작은 HTML 페이지를 설정했습니다. 이 비트는 특히 요청에 사용할 매개 변수가 없을 때 작동합니다. ngRoute 및 나머지 API를 기반으로 동적보기 만들기
TypeError: undefined is not a function
at Object.<anonymous> (http://localhost:8080/dashboard/js/factorys.js:11:16)
at Object.invoke (http://ajax.googleapis.com/ajax/libs/angularjs/1.2.28/angular.js:3965:17)
at http://ajax.googleapis.com/ajax/libs/angularjs/1.2.28/angular.js:3807:37
at getService (http://ajax.googleapis.com/ajax/libs/angularjs/1.2.28/angular.js:3929:39)
at invoke (http://ajax.googleapis.com/ajax/libs/angularjs/1.2.28/angular.js:3956:13)
at Object.instantiate (http://ajax.googleapis.com/ajax/libs/angularjs/1.2.28/angular.js:3976:23)
at $get (http://ajax.googleapis.com/ajax/libs/angularjs/1.2.28/angular.js:7315:28)
at link (http://ajax.googleapis.com/ajax/libs/angularjs/1.2.28/angular-route.js:907:26)
at nodeLinkFn (http://ajax.googleapis.com/ajax/libs/angularjs/1.2.28/angular.js:6752:13)
at compositeLinkFn (http://ajax.googleapis.com/ajax/libs/angularjs/1.2.28/angular.js:6146:13) <div class="container ng-scope" ng-view="">
내 각 스크립트
는 다음과 같이 :controllers.js :
var dashboardControllers = angular.module('dashboardControl',['ngRoute','dashboardFactory']);
dashboardApp.controller('PlayersController', function ($scope, $routeParams, Player) {
$scope.players = Player.findAll();
});
dashboardApp.controller('PlayerDetailsController', function ($scope, $routeParams, Player) {
$scope.playerId = $routeParams.playerId;
$scope.player = Player.get();
});
dashboardApp.controller('OverviewController', function ($scope, $routeParams, Overview) {
$scope.overview = Overview.query();
});
공장 마자 내가 다음 오류로 실패 PARAM를 추가하려고으로
.js :var dashboardFactories = angular.module('dashboardFactory',['ngResource']);
dashboardFactories.factory("Overview", ['$resource',
function ($resource) {
return $resource('webresources/overview/', {}, {
query: {method: 'GET', isArray: false}
});
}]);
dashboardFactories.factory("Player", ['$resource',
function ($scope, $resource) {
return $resource('webresources/player/:playerId', {}, {
findAll: {method: 'GET', isArray: true},
get: {method: 'GET', params: {playerId: $scope.playerId}, isArray: false}
});
}]);
개요 컨트롤러가 작동합니다. 플레이어 컨트롤러에 대한 오류 메시지가있는 것 같습니다.
IoC를 통해 $ scope를 공장에 삽입 할 수 없습니다. 그리고 또한 - 당신의 정의'dashboardFactories.factory ("Player",'틀렸어 - 배열의 하나의 param $ 리소스가 첫 번째 인자 * $ scope *'function ($ scope, $ resource) 대신에 사용되었다' –
만약 내가 어떻게하면 playerId 변수를 얻을 수 있을까요? –
UI-Router를 사용하고 ngroute와 작동하는 법을 거의 잊어 버렸습니다 ... 죄송합니다.하지만 내 대답에서 준 예제와 설명은 다음과 같아야합니다. 분명하고 오래된 ngRoute로 쉽게 재 작성 가능합니다 ... BTW - UI-Router를 확인하십시오.) –