Angular Service投掷“未知提供商”(Angular Service Throwing “Unknown Provider”)
我在转动轮子。 我正在尝试向我的控制器提供此服务的实例。 当我跑的时候,我明白了
JavaScript运行时错误:[$ injector:unpr]未知提供者:app.services.GithubServiceProvider < - app.services.GithubService < - app.githubViewer.UserController
这是件:
服务本身
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);
}
控制器
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:
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);
}
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
最满意答案
我添加了一个与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.
相关问答
更多-
按周分组连续几年(Group by Weeks for successive years)[2023-03-28]
我认为你想要创建一个用于在周开始和周末分组的构造,然后使用它来为你的聚合子句分组。 SET DATEFIRST 1 Select DATEADD(dd, -(DATEPART(dw, p.SellingDate)-1), p.SellingDate) AS [WeekStart], DATEADD(dd, 7-(DATEPART(dw, p.SellingDate)), p.SellingDate) AS [WeekEnd], SUM(Quantity), SUM(Revenue) From dbo. ... -
MYSQL通过Salesman和Weeks加入销售和分组的周表(MYSQL Join weeks table with Sales and Group by Salesman and Weeks)[2021-01-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.le ... -
当Promo == 1 ,我查看Promo为零的索引。 然后选择最近四周获得平均值。 df <- rbind(df, df) # get more rows to data df$AvgPrePromoSales <- sapply(1 : nrow(df), function(x) if(df$Promo[x] == 1) { ind <- which(df[1:x,]$Promo == 0) mean(df$Sales[ind[max(1, length ...
-
SQL查询比较2周(SQL Query to compare 2 weeks)[2023-05-22]
根据我的理解,您希望在两周内执行单独的查询,并且您希望这两个查询都为所有国家/地区生成行,而不管所有国家/地区是否都有任何呼叫。 为了达到这个目的,你需要使用LEFT OUTER JOINS。 下面的代码应该保证在Country表中找到的每个国家都有一行,即使两个总和都是0。 SELECT country, SUM(CASE WHEN actstatus IN (5,105) THEN 1 ELSE 0 END) AS TotalCalls, SUM(CASE WHEN actstatus ... -
Postgresql数过去数周(Postgresql count by past weeks)[2023-07-25]
select t.id, count(week = 0 or null) as wk0, count(week = 1 or null) as wk1, count(week = 2 or null) as wk2, count(week = 3 or null) as wk3 from teams t left join loan_files lf on lf.team_id = t.id and loan_type <> 2 cro ... -
SQL查询,用于获取过去17周内按周分组的数据(SQL query to get the data grouped by weeks for the last 17 weeks)[2023-03-12]
首先,我建议如果您在两个表上没有以下索引,请考虑添加它们以支持我们准备做的事情以及更多。 --===== If you don't already have them, consider adding these indexes CREATE NONCLUSTERED INDEX By_OrderDate ON [dbo].OrdMaster([OrderDate]) INCLUDE ([SalesOrder]) ; CREATE NONCLUSTERED INDEX By_SalesOrde ... -
Sql小提琴演示 这是一个简化版本,只需要一个week_id和sales SELECT S1.weekid start_week, MAX(S2.weekid) end_week, SUM (S2.sales) FROM Sales S1 JOIN Sales S2 ON S2.weekid BETWEEN S1.weekid and S1.weekid + 11 WHERE S1.weekid BETWEEN 1 and 25 -- your search range GROUP BY ...
-
假设您的timestamp列称为timestamp ,您可以: SELECT CONCAT(YEAR(timestamp), '/', WEEK(timestamp)) AS week 然后检索特定范围,按周排序等。 Assuming your timestamp column is called timestamp, you can: SELECT CONCAT(YEAR(timestamp), '/', WEEK(timestamp)) AS week and then retrieve specifi ...
-
如何将没有作为零值销售的商品周添加到我的SQL查询中?(How to add the weeks with no items sold as zero values to my SQL query?)[2022-06-01]
您要做的第一件事是在您的模型名称和周之间创建一个笛卡尔联接。 就像是: SELECT DISTINCT [Query - Sales].ModelName, tblWeek.WeekNum FROM [Query - Sales] LEFT JOIN tblWeek 这将为每个模型名称每周创建一条记录。 然后,您想要将实际数据加入此查询: SELECT qryA.*, Count([Query - Sales].OutDate) AS CountOfOutDate FROM ( SELECT DISTI ... -
SQL结果按周,日分组(SQL results grouped by Weeks, Day)[2022-09-26]
只需使用条件聚合: select datename(weekday, fce.date) as dayOfWeek, servingTime, sum(case when weeks = 1 then sale else 0 end) as Week_1, sum(case when weeks = 2 then sale else 0 end) as Week_2, sum(case when weeks = 3 then sale else 0 end) as ...