简体   繁体   中英

AngularJS : controller with factory

I am new to Angular and I am creating my first app right now. I have a factory in place and my controller should be pulling in data from my source, however I keep on getting this error . My factory is called SpreadsheetFactory.

I have the code for my controller below. Any help is appreciated, thanks!

(function () {

     angular
    .module('beerApp')
    .controller('appController', appController, ['$scope', 'SpreadsheetFactory']);

    function appController($scope, SpreadsheetFactory) {

        SpreadsheetFactory.getData().then( function (data) {
            console.log(data)
        });

        // $scope.brews = [];

        return data;
    }

})();

This line is wrong:

.controller('appController', appController, ['$scope', 'SpreadsheetFactory']);

It should be:

.controller('appController', ['$scope', 'SpreadsheetFactory', appController]);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM