Javascript 在控制器之间传递数据的服务创建中出现问题?

Javascript 在控制器之间传递数据的服务创建中出现问题?,javascript,angularjs,angular-services,angular-controller,Javascript,Angularjs,Angular Services,Angular Controller,我想从登录控制器传递数据以验证移动控制器,为此,我提供了一个服务来处理控制器之间的数据通信。但我有个错误 错误:$injector:unpr未知提供程序 这是我的服务login.service.js (function () { 'use strict'; angular .module('app.pages.auth.login',[]) .factory('dataService', dataService); /** @ngInj

我想从登录控制器传递数据以验证移动控制器,为此,我提供了一个服务来处理控制器之间的数据通信。但我有个错误

错误:$injector:unpr未知提供程序

这是我的服务login.service.js

(function ()
{
    'use strict';

    angular
        .module('app.pages.auth.login',[])
        .factory('dataService', dataService);

    /** @ngInject */
    function dataService(){

        var sendarr = [];

        var addData = function(newObj) {
            sendarr.push(newObj);
        };

         var getData = function(){
            return sendarr;
        };

        return {
            addData: addData,
            getData: getData
        };

    }

})();
(function ()
{
    'use strict';

    angular
        .module('fuse')
        .controller('LoginController', LoginController);

    /** @ngInject */
    function LoginController(msApi,$state,dataService)
    {
        // Data
        var vm = this;

        vm.login = login;
        vm.startApp = startApp;
        vm.fbLogin = fbLogin;
        var auth2;
        // Methods
        function fbLogin(){
            FB.login(function(response){
                if(response.status=='connected'){
                    testAPI();
                }
                else if(response.status == 'not_authorized'){
                    console.log('error');
                }
                else{
                    console.log('please log in');
                }
            });
        }

        function testAPI() {
            console.log('Welcome!  Fetching your information.... ');
            FB.api('/me', function(response) {
                console.log('Successful login for: ' + response.name);

            });
        }

        function startApp(){
            gapi.load('auth2', function(){
            // Retrieve the singleton for the GoogleAuth library and set up the client.
                auth2 = gapi.auth2.init({
                client_id: '990822731291-21sdd22ujqc78l1q2i2lmf5hfe5satj1.apps.googleusercontent.com',
                cookiepolicy: 'single_host_origin',
                fetch_basic_profile: 'true',
                // Request scopes in addition to 'profile' and 'email'
                //scope: 'additional_scope'
                });
                attachSignin(document.getElementById('customGoogleBtn'));
             });
        }

        function attachSignin(element) {
            auth2.attachClickHandler(element, {},
                function(googleUser) {
                    var profile = googleUser.getBasicProfile();
                    console.log('ID: ' + profile.getId()); // Do not send to your backend! Use an ID token instead.
                    console.log('Name: ' + profile.getName());
                    console.log('Image URL: ' + profile.getImageUrl());
                    console.log('Email: ' + profile.getEmail());
                    var pushData = [profile.getId(), profile.getName(), profile.getEmail()];
                    console.log(pushData);
                    dataService.addData(pushData);
                    $state.go('app.pages_auth_verify-mobile')
                }, 
                function(error) {
                    alert(JSON.stringify(error, undefined, 2));
            });
        }

        function login(){
            var jsonData = {"mobile":vm.form.mobile};
            msApi.request('login.credentials@save',jsonData,
                // SUCCESS
                function (response)
                {
                   console.log(response.error);
                    if(response.error == 1){
                        vm.form.mobileErrorFlag = true;
                    }
                    if(response.error == 0){
                        vm.form.mobileErrorFlag = false;
                    }
                },
                // ERROR
                function (response)
                {
                    alert(JSON.stringify(response));
                }
            )
        }



    }
})();
(function ()
{
    'use strict';

    angular
        .module('app.pages.auth.verify-mobile')
        .controller('VerifyMobileController', VerifyMobileController);

    /** @ngInject */
    function VerifyMobileController(dataService)
    {
        var data = dataService.getData();

        alert(data);
    }
})();
这是我的第一个控制器login.controller.js

(function ()
{
    'use strict';

    angular
        .module('app.pages.auth.login',[])
        .factory('dataService', dataService);

    /** @ngInject */
    function dataService(){

        var sendarr = [];

        var addData = function(newObj) {
            sendarr.push(newObj);
        };

         var getData = function(){
            return sendarr;
        };

        return {
            addData: addData,
            getData: getData
        };

    }

})();
(function ()
{
    'use strict';

    angular
        .module('fuse')
        .controller('LoginController', LoginController);

    /** @ngInject */
    function LoginController(msApi,$state,dataService)
    {
        // Data
        var vm = this;

        vm.login = login;
        vm.startApp = startApp;
        vm.fbLogin = fbLogin;
        var auth2;
        // Methods
        function fbLogin(){
            FB.login(function(response){
                if(response.status=='connected'){
                    testAPI();
                }
                else if(response.status == 'not_authorized'){
                    console.log('error');
                }
                else{
                    console.log('please log in');
                }
            });
        }

        function testAPI() {
            console.log('Welcome!  Fetching your information.... ');
            FB.api('/me', function(response) {
                console.log('Successful login for: ' + response.name);

            });
        }

        function startApp(){
            gapi.load('auth2', function(){
            // Retrieve the singleton for the GoogleAuth library and set up the client.
                auth2 = gapi.auth2.init({
                client_id: '990822731291-21sdd22ujqc78l1q2i2lmf5hfe5satj1.apps.googleusercontent.com',
                cookiepolicy: 'single_host_origin',
                fetch_basic_profile: 'true',
                // Request scopes in addition to 'profile' and 'email'
                //scope: 'additional_scope'
                });
                attachSignin(document.getElementById('customGoogleBtn'));
             });
        }

        function attachSignin(element) {
            auth2.attachClickHandler(element, {},
                function(googleUser) {
                    var profile = googleUser.getBasicProfile();
                    console.log('ID: ' + profile.getId()); // Do not send to your backend! Use an ID token instead.
                    console.log('Name: ' + profile.getName());
                    console.log('Image URL: ' + profile.getImageUrl());
                    console.log('Email: ' + profile.getEmail());
                    var pushData = [profile.getId(), profile.getName(), profile.getEmail()];
                    console.log(pushData);
                    dataService.addData(pushData);
                    $state.go('app.pages_auth_verify-mobile')
                }, 
                function(error) {
                    alert(JSON.stringify(error, undefined, 2));
            });
        }

        function login(){
            var jsonData = {"mobile":vm.form.mobile};
            msApi.request('login.credentials@save',jsonData,
                // SUCCESS
                function (response)
                {
                   console.log(response.error);
                    if(response.error == 1){
                        vm.form.mobileErrorFlag = true;
                    }
                    if(response.error == 0){
                        vm.form.mobileErrorFlag = false;
                    }
                },
                // ERROR
                function (response)
                {
                    alert(JSON.stringify(response));
                }
            )
        }



    }
})();
(function ()
{
    'use strict';

    angular
        .module('app.pages.auth.verify-mobile')
        .controller('VerifyMobileController', VerifyMobileController);

    /** @ngInject */
    function VerifyMobileController(dataService)
    {
        var data = dataService.getData();

        alert(data);
    }
})();
这是我的第二个控制器,我在其中接收数据验证mobile.controller.js

(function ()
{
    'use strict';

    angular
        .module('app.pages.auth.login',[])
        .factory('dataService', dataService);

    /** @ngInject */
    function dataService(){

        var sendarr = [];

        var addData = function(newObj) {
            sendarr.push(newObj);
        };

         var getData = function(){
            return sendarr;
        };

        return {
            addData: addData,
            getData: getData
        };

    }

})();
(function ()
{
    'use strict';

    angular
        .module('fuse')
        .controller('LoginController', LoginController);

    /** @ngInject */
    function LoginController(msApi,$state,dataService)
    {
        // Data
        var vm = this;

        vm.login = login;
        vm.startApp = startApp;
        vm.fbLogin = fbLogin;
        var auth2;
        // Methods
        function fbLogin(){
            FB.login(function(response){
                if(response.status=='connected'){
                    testAPI();
                }
                else if(response.status == 'not_authorized'){
                    console.log('error');
                }
                else{
                    console.log('please log in');
                }
            });
        }

        function testAPI() {
            console.log('Welcome!  Fetching your information.... ');
            FB.api('/me', function(response) {
                console.log('Successful login for: ' + response.name);

            });
        }

        function startApp(){
            gapi.load('auth2', function(){
            // Retrieve the singleton for the GoogleAuth library and set up the client.
                auth2 = gapi.auth2.init({
                client_id: '990822731291-21sdd22ujqc78l1q2i2lmf5hfe5satj1.apps.googleusercontent.com',
                cookiepolicy: 'single_host_origin',
                fetch_basic_profile: 'true',
                // Request scopes in addition to 'profile' and 'email'
                //scope: 'additional_scope'
                });
                attachSignin(document.getElementById('customGoogleBtn'));
             });
        }

        function attachSignin(element) {
            auth2.attachClickHandler(element, {},
                function(googleUser) {
                    var profile = googleUser.getBasicProfile();
                    console.log('ID: ' + profile.getId()); // Do not send to your backend! Use an ID token instead.
                    console.log('Name: ' + profile.getName());
                    console.log('Image URL: ' + profile.getImageUrl());
                    console.log('Email: ' + profile.getEmail());
                    var pushData = [profile.getId(), profile.getName(), profile.getEmail()];
                    console.log(pushData);
                    dataService.addData(pushData);
                    $state.go('app.pages_auth_verify-mobile')
                }, 
                function(error) {
                    alert(JSON.stringify(error, undefined, 2));
            });
        }

        function login(){
            var jsonData = {"mobile":vm.form.mobile};
            msApi.request('login.credentials@save',jsonData,
                // SUCCESS
                function (response)
                {
                   console.log(response.error);
                    if(response.error == 1){
                        vm.form.mobileErrorFlag = true;
                    }
                    if(response.error == 0){
                        vm.form.mobileErrorFlag = false;
                    }
                },
                // ERROR
                function (response)
                {
                    alert(JSON.stringify(response));
                }
            )
        }



    }
})();
(function ()
{
    'use strict';

    angular
        .module('app.pages.auth.verify-mobile')
        .controller('VerifyMobileController', VerifyMobileController);

    /** @ngInject */
    function VerifyMobileController(dataService)
    {
        var data = dataService.getData();

        alert(data);
    }
})();

您的控制器和服务来自两个不同的模块OK。那么,有没有办法解决不同模块的问题呢?你需要注入它们并解决依赖关系,我不知道怎么做?你能解释清楚一点吗?你的控制器和服务来自两个不同的模块。那么,有没有办法解决不同模块的问题呢?你需要注入它们并解决依赖关系,我不知道怎么做?你能再解释清楚一点吗