1

次のエラーが発生します。既にコントローラーにファクトリを注入していますが、この問題の解決にはヘルプと提案が非常に役立ちます。


Error: [$injector:unpr] http://errors.angularjs.org/1.3.16/$injector/unpr?p0=<div ng-view="" class="ng-scope">copeProvider%20%3C-%20%24scope%20%3C-%customerFactory
        at Error (native)
        at https://code.angularjs.org/1.3.16/angular.min.js:6:417
        at https://code.angularjs.org/1.3.16/angular.min.js:38:7
        at Object.d [as get] (https://code.angularjs.org/1.3.16/angular.min.js:36:13)
        at https://code.angularjs.org/1.3.16/angular.min.js:38:81
        at d (https://code.angularjs.org/1.3.16/angular.min.js:36:13)
        at Object.e [as invoke] (https://code.angularjs.org/1.3.16/angular.min.js:36:283)
        at Object.$get (https://code.angularjs.org/1.3.16/angular.min.js:34:268)
        at Object.e [as invoke] (https://code.angularjs.org/1.3.16/angular.min.js:36:315)
        at https://code.angularjs.org/1.3.16/angular.min.js:38:110(anonymous function) @ angular.js:11699$get @ angular.js:8628Xc @ angular.js:8292M @ angular.js:7800g @ angular.js:7149(anonymous function) @ angular.js:7028$get.h @ angular.js:7167l @ angular.js:7827x @ angular-route.js:935$get.m.$broadcast @ angular.js:14866(anonymous function) @ angular-route.js:618(anonymous function) @ angular.js:13292$get.m.$eval @ angular.js:14547$get.m.$digest @ angular.js:14363$get.m.$apply @ angular.js:14652l @ angular.js:9734P @ angular.js:9924H.onload @ angular.js:9865

customerFactory.js

(function () {

    var customerApp = angular.module('demoApp');

    function customerFactory($scope) {

        var customers = [{
            id: 1,
            name: 'a1',
            city: 'P1',
            orderTotal: '10.78',
            joined: '1990-12-10',
            order: [{
                id: 1,
                product: 'Shoes',
                total: 10.78
                        }]
            }, {
            id: 2,
            name: 'A2',
            city: 'I2',
            orderTotal: '12.99',
            joined: '2003-4-7',
            order: [{
                id: 2.1,
                product: 'Shirt',
                total: 10
                }, {
                id: 2.2,
                product: 'Shaker',
                total: 2.99
                    }]
                }, {
            id: 3,
            name: 'K3',
            city: 'K3',
            orderTotal: '6.787',
            joined: '2015-9-9',
            order: [{
                id: 3.1,
                product: 'Table',
                total: 4.00
                    }, {
                id: 3.2,
                product: 'chair',
                total: 2.787
                        }]
                }, {
            id: 4,
            name: 'R1',
            city: 'A1',
            orderTotal: '12.00',
            joined: '2003-12-1',
            order: [{
                id: 4.1,
                product: 'House',
                total: 9
                    }, {
                id: 4.2,
                product: 'car',
                total: 3
                        }]
                 }];

        // defining the factory object here
        var factory = {};
        factory.getCustomers = function () {
            return customers;
        };

        return factory;
    };

    customerApp.factory('customerFactory', customerFactory);
}());

ここにplnkrリンクがあります http://plnkr.co/edit/A4XPuRxPSIajmh5mCAcN

4

1 に答える 1

0

$scope実装からパラメーターを削除しますfactory-そこでは使用$scopeしていません。

$scopeパラメータは、表示されているエラーの原因です。

Angular は認識していない依存関係を注入しようとしています。

$scope工場では必要ありません-そこでは使用していないためです。

関数factory定義は次のようになります。

function customerFactory() {

これが実際のプランカーです: http://plnkr.co/edit/uNJEjTBd1fhnCo4rTVTq?p=preview

(プランカーで動作するようにルートも変更しました)。

于 2015-06-30T23:04:44.440 に答える