angular.js - AngularJS provider inline injection method registration service error
PHP中文网
PHP中文网 2017-05-15 17:04:46
0
2
799
app.provider("myService",['$http',function(){
            return {
                myUrl:null,
                setUrl:function(url) {
                    myUrl = url;
                },
                $get:function($http) {
                    return {
                        getPerson:function() {
                            return $http({
                                method:"GET",
                                url:myUrl
                            });
                        }
                    }
                 }
            }
        }]);

This code reported such an error:

ionic.bundle.min.js:40 Uncaught Error: [$injector:modulerr] http://errors.angularjs.org/1.5.3/$injector/modulerr?p0=myApp&p1=Error%3A%2…st%3A63342%2FIonicDemo%2Flib%2Fionic%2Fjs%2Fionic.bundle.min.js%3A73%3A340

What kind of error is this? What is wrong with the above code

PHP中文网
PHP中文网

认证0级讲师

reply all(2)
阿神

Will your code be compressed? If so, it is probably because there is no explicit dependency injection after $get

app.provider("myService",['$http',function($http){
            return {
                myUrl:null,
                setUrl:function(url) {
                    myUrl = url;
                },
                $get:['$http',function($http) {
                    return {
                        getPerson:function() {
                            return $http({
                                method:"GET",
                                url:myUrl
                            });
                        }
                    }
                 }]
            }
        }]);
Peter_Zhu

app.provider("myService",['$http',function(){
Change the above to function($http)
You forgot to write the parameters, so $injector error will be reported

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template