首页 \ 问答 \ Angular Service投掷“未知提供商”(Angular Service Throwing “Unknown Provider”)

Angular Service投掷“未知提供商”(Angular Service Throwing “Unknown Provider”)

我在转动轮子。 我正在尝试向我的控制器提供此服务的实例。 当我跑的时候,我明白了

JavaScript运行时错误:[$ injector:unpr]未知提供者:app.services.GithubServiceProvider < - app.services.GithubService < - app.githubViewer.UserController

这是件:

  1. 服务本身

    module app.services {
    'use strict';
    
    export interface IGithubService {
        getUser(username: string): ng.IPromise<any>;
    }
    
    export class GithubService implements IGithubService {
    
        githubUrl: string = 'https://api.github.com/';
    
        static $inject = ['$http'];
        constructor(private $http: ng.IHttpService) {
    
        }
        getUser(username: string): angular.IPromise<any> {
            return this.$http.get(this.githubUrl + "users/" + username)
                .then(response => response.data);
        }
    }
    
    angular
        .module('app.services')
        .service('app.services.GithubService', GithubService);
    

    }

  2. 控制器

    module app.githubViewer {
    'use strict';
    
    interface IUserControllerScope { //scope definitions
    
    }
    
    class UserController implements IUserControllerScope {
    
        static $inject = ['app.services.GithubService', '$route'];
        constructor(githubService: app.services.IGithubService, $route: ng.route.IRouteService) {
       //...
        }
    
    }
    
    angular
        .module('app.githubViewer')
        .controller('app.githubViewer.UserController', UserController);
    

    }

更新,我在这里查看了这个常见问题列表 ,看起来它们都是有序的。 代码如下:

这是我的主要模块声明:

((): void => {
    'use strict';

    angular
        .module('app', [
            'app.core',
            'app.services',
            /*
             *Feature Modules
             */
            'app.githubViewer'
        ]);
})();

这是服务模块声明:

((): void => {
    'use strict';

    angular
        .module('app.services', []);
})();

我已经进行了三次检查,以确保将脚本添加到页面中。

如果还有什么我应该在这里发布,请告诉我。 我是Angular和TypeScript的初学者。


I'm spinning my wheels on this. I'm trying to provide an instance of this service to my controller. When I run it, I get

JavaScript runtime error: [$injector:unpr] Unknown provider: app.services.GithubServiceProvider <- app.services.GithubService <- app.githubViewer.UserController

Here are the pieces:

  1. Service itself

    module app.services {
    'use strict';
    
    export interface IGithubService {
        getUser(username: string): ng.IPromise<any>;
    }
    
    export class GithubService implements IGithubService {
    
        githubUrl: string = 'https://api.github.com/';
    
        static $inject = ['$http'];
        constructor(private $http: ng.IHttpService) {
    
        }
        getUser(username: string): angular.IPromise<any> {
            return this.$http.get(this.githubUrl + "users/" + username)
                .then(response => response.data);
        }
    }
    
    angular
        .module('app.services')
        .service('app.services.GithubService', GithubService);
    

    }

  2. The Controller

    module app.githubViewer {
    'use strict';
    
    interface IUserControllerScope { //scope definitions
    
    }
    
    class UserController implements IUserControllerScope {
    
        static $inject = ['app.services.GithubService', '$route'];
        constructor(githubService: app.services.IGithubService, $route: ng.route.IRouteService) {
       //...
        }
    
    }
    
    angular
        .module('app.githubViewer')
        .controller('app.githubViewer.UserController', UserController);
    

    }

Update, I looked at this list of common issues here, and it looks like it's all in order. Code is below:

Here is my main module declaration:

((): void => {
    'use strict';

    angular
        .module('app', [
            'app.core',
            'app.services',
            /*
             *Feature Modules
             */
            'app.githubViewer'
        ]);
})();

And here is the service module declaration:

((): void => {
    'use strict';

    angular
        .module('app.services', []);
})();

I have triple checked to make sure the scripts are added to the page.

Please let me know if there is anything else I should post here. I'm a beginner on Angular and TypeScript.


原文:https://stackoverflow.com/questions/37756529
更新时间:2023-09-17 08:09

最满意答案

我添加了一个与weekstll的联接。 你可以查看下面的查询。 我希望这有帮助。

SELECT ROUND(SUM(n.newBalance), 2) AS newB, weeks, u.username
  FROM (
    SELECT 
        j.leadid AS custid, 
        w.weekno AS weeks,
        j.price / (SELECT count(*) FROM assignmentstbl a WHERE a.custid=j.leadid) AS newBalance
    FROM jobbooktbl j
    join weekstbl w on j.convertdate between weekstart and date(weekstart + interval 6 day )
    WHERE j.convertdate BETWEEN '2017-01-02' AND '2017-07-31' 
    AND j.status IN (4,6,7,8,11)
    ) n
    JOIN assignmentstbl a USING (custid)
    JOIN usertbl u USING (userid)
    -- WHERE a.userid=5
    GROUP BY weeks, a.userid
    ORDER BY newB DESC

这是一个更新的答案。

select userid, username, week, year, fvalue
from ( select sub3.*, 
if(@previous = userid, @value1 := @value1 + value, @value1 := value ) fvalue,
@previous := userid
from (select distinct ut.userid, ut.username, 
week(date) as week,year(date) as year ,coalesce(sub2.newB,0) as value
from ( SELECT (CURDATE() - INTERVAL c.number DAY) AS date
FROM (SELECT singles + tens + hundreds number FROM 
( SELECT 0 singles
UNION ALL SELECT   1 UNION ALL SELECT   2 UNION ALL SELECT   3
UNION ALL SELECT   4 UNION ALL SELECT   5 UNION ALL SELECT   6
UNION ALL SELECT   7 UNION ALL SELECT   8 UNION ALL SELECT   9
) singles JOIN 
(SELECT 0 tens
UNION ALL SELECT  10 UNION ALL SELECT  20 UNION ALL SELECT  30
UNION ALL SELECT  40 UNION ALL SELECT  50 UNION ALL SELECT  60
UNION ALL SELECT  70 UNION ALL SELECT  80 UNION ALL SELECT  90
) tens  JOIN 
(SELECT 0 hundreds
UNION ALL SELECT  100 UNION ALL SELECT  200 UNION ALL SELECT  300
UNION ALL SELECT  400 UNION ALL SELECT  500 UNION ALL SELECT  600
UNION ALL SELECT  700 UNION ALL SELECT  800 UNION ALL SELECT  900
) hundreds
ORDER BY number DESC) c  ) abc 
cross join usertbl ut
left join (
  SELECT ROUND(SUM(n.newBalance), 2) AS newB, weeks, years,a.userid, u.username
  FROM (
    SELECT 
        j.leadid AS custid, 
        w.weekno AS weeks,
    year(weekstart) as years,
        j.price / (SELECT count(*) FROM assignmentstbl a WHERE a.custid=j.leadid) AS newBalance
    FROM jobbooktbl j
    join weekstbl w on j.convertdate between weekstart and date(weekstart + interval 6 day )
    WHERE j.convertdate BETWEEN '2017-01-02' AND '2017-07-31' 
    AND j.status IN (4,6,7,8,11)
    ) n
    JOIN assignmentstbl a USING (custid)
    JOIN usertbl u on u.userid = a.userid
    GROUP BY weeks, a.userid
) sub2 on sub2.userid = ut.userid 
and weeks = week(date)
and years = year(date)
where date between '2017-01-02' AND '2017-07-31' 
order by userid,year(date), week(date) ) sub3 ) sub4
order by year, week, userid

注意:我建议创建dim_time表,它存储日期的所有相关信息。

说明:

1)子查询名称:abc这将根据您的输入生成周和年。 之后用usertbl交叉加入你的结果。 在最终输出中需要多少行。 现在我们根据您的要求添加值。

2)子查询名称:sub2
这会产生您所需的结果,但它不显示0值。

3)现在1左连接2这给你结果(按星期分组然后按推销员)。 更改order by子句只是为了获得预期的输出。
这成为你的sub3。 这是必要的,因为我们必须将前一个值加到下一个值。

4)创建varialbe @previous和@ value1因为我们已经基于userid对结果进行了排序。 现在第一行来了,它检查下面的条件。 然后它转到else部分因为它不匹配,将userid存储在@previous中。 现在它会占用第二行,它会将前一个值添加到下一行,因为条件已满足。 相似它会添加你的结果,直到新用户ID来。

Condtion:

MySQL (@previous = userid,  @value1 := @value1 + value ,@value1 := value)

if @previous = userid 
then @value1 := @value1 + value 
else @value1 := value; 

我希望这将有所帮助。


I have added one join with weekstbl. you can check below query. I hope this helps.

SELECT ROUND(SUM(n.newBalance), 2) AS newB, weeks, u.username
  FROM (
    SELECT 
        j.leadid AS custid, 
        w.weekno AS weeks,
        j.price / (SELECT count(*) FROM assignmentstbl a WHERE a.custid=j.leadid) AS newBalance
    FROM jobbooktbl j
    join weekstbl w on j.convertdate between weekstart and date(weekstart + interval 6 day )
    WHERE j.convertdate BETWEEN '2017-01-02' AND '2017-07-31' 
    AND j.status IN (4,6,7,8,11)
    ) n
    JOIN assignmentstbl a USING (custid)
    JOIN usertbl u USING (userid)
    -- WHERE a.userid=5
    GROUP BY weeks, a.userid
    ORDER BY newB DESC

Here is an updated answer.

select userid, username, week, year, fvalue
from ( select sub3.*, 
if(@previous = userid, @value1 := @value1 + value, @value1 := value ) fvalue,
@previous := userid
from (select distinct ut.userid, ut.username, 
week(date) as week,year(date) as year ,coalesce(sub2.newB,0) as value
from ( SELECT (CURDATE() - INTERVAL c.number DAY) AS date
FROM (SELECT singles + tens + hundreds number FROM 
( SELECT 0 singles
UNION ALL SELECT   1 UNION ALL SELECT   2 UNION ALL SELECT   3
UNION ALL SELECT   4 UNION ALL SELECT   5 UNION ALL SELECT   6
UNION ALL SELECT   7 UNION ALL SELECT   8 UNION ALL SELECT   9
) singles JOIN 
(SELECT 0 tens
UNION ALL SELECT  10 UNION ALL SELECT  20 UNION ALL SELECT  30
UNION ALL SELECT  40 UNION ALL SELECT  50 UNION ALL SELECT  60
UNION ALL SELECT  70 UNION ALL SELECT  80 UNION ALL SELECT  90
) tens  JOIN 
(SELECT 0 hundreds
UNION ALL SELECT  100 UNION ALL SELECT  200 UNION ALL SELECT  300
UNION ALL SELECT  400 UNION ALL SELECT  500 UNION ALL SELECT  600
UNION ALL SELECT  700 UNION ALL SELECT  800 UNION ALL SELECT  900
) hundreds
ORDER BY number DESC) c  ) abc 
cross join usertbl ut
left join (
  SELECT ROUND(SUM(n.newBalance), 2) AS newB, weeks, years,a.userid, u.username
  FROM (
    SELECT 
        j.leadid AS custid, 
        w.weekno AS weeks,
    year(weekstart) as years,
        j.price / (SELECT count(*) FROM assignmentstbl a WHERE a.custid=j.leadid) AS newBalance
    FROM jobbooktbl j
    join weekstbl w on j.convertdate between weekstart and date(weekstart + interval 6 day )
    WHERE j.convertdate BETWEEN '2017-01-02' AND '2017-07-31' 
    AND j.status IN (4,6,7,8,11)
    ) n
    JOIN assignmentstbl a USING (custid)
    JOIN usertbl u on u.userid = a.userid
    GROUP BY weeks, a.userid
) sub2 on sub2.userid = ut.userid 
and weeks = week(date)
and years = year(date)
where date between '2017-01-02' AND '2017-07-31' 
order by userid,year(date), week(date) ) sub3 ) sub4
order by year, week, userid

Note: I would suggest to create dim_time table which stores all related information of date.

Explanation:

1) Sub Query Name: abc This will generate week and year based on your input. After that cross join your result with usertbl. That many number of rows you want in your final output. Now we have add values as per your requiremnent.

2) Sub Query Name: sub2
This produces your required result but it is not showing 0 values.

3) Now 1 left join 2 This gives you result as (Grouped by Week then By Salesman). Change order by clause just to get expected output.
This becomes your sub3. This is necessory because we have to sum previous value to next value.

4) Create varialbe @previous and @value1 As we have sorted our result based on userid. Now first row come and it checks below condition. Then it goes to else part because it not matching, store userid in @previous. It excutes second row now it will add previous value to next row because condition is satisfied. Similary it will add your result till new userid comes.

Condtion:

MySQL (@previous = userid,  @value1 := @value1 + value ,@value1 := value)

if @previous = userid 
then @value1 := @value1 + value 
else @value1 := value; 

I hope this will help.

相关问答

更多

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。