0

So I want to inlcude a own service to a angular-script. But it won't find the servicename, when I put it into the params of my script.

I got this script(script.js):

(function(){
    var app = angular.module("Viewer", []);
    var MainCtrl = function($scope, viewthis, $http, $interval, $log){
         Magic;
    };
    app.controller("MainController", MainCtrl);
}());

And this is my service(viewthis.js):

(function()
{
    var viewthis = function($http)
    {
        Methods, Magic;

        //there is this return in a method:
        return $http.get("https://api.github.com/users/" + username);

        return
        {
            method: method
        };
    };

    var module = angular.module("Viewer");
    module.factory("viewthis", viewthis);

}());

This is the HTML head:

<head>
    <script src="angular.js"></script>
    <link href="style.css" rel="stylesheet" />
    <script src="script.js"></script>
    <script src="viewthis.js"></script>
</head>

The FireFox-Developement-tool says this in the console:

"Error: [$injector:unpr] http://errors.angularjs.org/1.2.26/$injector/unpr?p0=githubProvider%20%3C-%20github
C/<@file:///Z:/AngularTut/angular.js:6:443
gc/l.$injector<@file:///Z:/AngularTut/angular.js:36:196
c@file:///Z:/AngularTut/angular.js:34:300
gc/p.$injector<@file:///Z:/AngularTut/angular.js:36:266
c@file:///Z:/AngularTut/angular.js:34:300
d@file:///Z:/AngularTut/angular.js:35:1
f/<.instantiate@file:///Z:/AngularTut/angular.js:35:163
Pd/this.$get</<@file:///Z:/AngularTut/angular.js:67:415
N/<@file:///Z:/AngularTut/angular.js:54:23
r@file:///Z:/AngularTut/angular.js:7:369
N@file:///Z:/AngularTut/angular.js:53:393
g@file:///Z:/AngularTut/angular.js:47:256
g@file:///Z:/AngularTut/angular.js:47:256
z/<@file:///Z:/AngularTut/angular.js:46:374
fc/c/</<@file:///Z:/AngularTut/angular.js:18:310
Zd/this.$get</k.prototype.$eval@file:///Z:/AngularTut/angular.js:112:57
Zd/this.$get</k.prototype.$apply@file:///Z:/AngularTut/angular.js:112:341
fc/c/<@file:///Z:/AngularTut/angular.js:18:268
d@file:///Z:/AngularTut/angular.js:35:27
fc/c@file:///Z:/AngularTut/angular.js:18:248
fc@file:///Z:/AngularTut/angular.js:18:380
Xc@file:///Z:/AngularTut/angular.js:17:422
@file:///Z:/AngularTut/angular.js:215:30
a@file:///Z:/AngularTut/angular.js:145:67
oe/c/<@file:///Z:/AngularTut/angular.js:31:223
r@file:///Z:/AngularTut/angular.js:7:288
oe /c@file:///Z:/AngularTut/angular.js:31:207
"

If i delete "viewthis" from the params, it will build the page. With "viewthis" in it, not.

And if its easy to solve, I am sorry. I am a newbie in javascript...

NewOutlaw
  • 64
  • 8
  • What is `githubProvider`? Post missing code. – dfsq Oct 23 '14 at 11:24
  • Oh, I am sorry. I renamend method "github" to "viewthis" for this post. In it, there is a method which returns: $http.get("https://api.github.com/users/" + username) Perhaps this will help. Sorry. – NewOutlaw Oct 23 '14 at 11:33
  • You have `return { method: method }` with the opening brace in a new line. DON'T!!! Put it in the same line... E.g. see [this](http://stackoverflow.com/questions/3641519/why-does-a-results-vary-based-on-curly-brace-placement) – Nikos Paraskevopoulos Oct 23 '14 at 12:33
  • DUUUDE!! That is the solution! I can't believe it! Didn't know that this is illegal in js... Thank you!! – NewOutlaw Oct 23 '14 at 12:38

0 Answers0