Angular 2 / Typescript重新导出:“找不到模块:无法解析[...]”(Angular 2/ Typescript Re-export: “Module not found: Can't resolve […]”)
我正在使用Angular 2和Typescript。 我正在尝试创建一个类集合,每个类都在自己的文件中定义,并希望能够使用单个(或许可能)更多行来导入它们。
像这样的东西:
// lib/foo.ts export class Foo {} // lib/bar.ts export class Bar {} // lib/index.d.ts export * from './foo'; export * from './bar'; // app.component.ts import * as lib from './lib'; ... let foo = new lib.Foo(); let bar = new lib.Bar();
我通过互联网搜索了一段时间,并在我的代码中尝试了很多可能的方法,但它们似乎都没有用。 例如,在此Stackoverflow答案中 ,它似乎与我的语法相同(上面的代码)。
那么也许这是一个特定角度的问题?
这是我收到的完整错误消息,当使用“ng serve”构建时(在角度cli上):
ERROR in ./src/app/api-module/services/factory.service.ts Module not found: Error: Can't resolve '../sketch-objects' in 'D:\[...]\PhpStorm\vector-sketch\src\app\api-module\services' @ ./src/app/api-module/services/factory.service.ts 8:0-51
虽然具有以下作品的导入:
import {Scene} from '../sketch-objects/scene';
只是为了理解:我正在编写一个处理threeJS的应用程序,并希望创建某种工厂,根据给定的特定字符串构建threeJS对象(或者更确切地说,围绕threeJS对象的包装器)。例如我有功能// factory.service.ts import * as lib from './lib' ... create(objectType: string): any { let threeObject = lib[objectType](); return threeObject; }
我感谢任何帮助,谢谢。
bertioooI'm working with Angular 2 and Typescript. I'm trying to create a collection of classes, each defined in its own file, and want to be able to import them with a single (or perhaps) more lines.
Something similar like this:
// lib/foo.ts export class Foo {} // lib/bar.ts export class Bar {} // lib/index.d.ts export * from './foo'; export * from './bar'; // app.component.ts import * as lib from './lib'; ... let foo = new lib.Foo(); let bar = new lib.Bar();
I searched a while through the internet, and tried a lot of possible ways in my code, but none of them seems to work. For example, in this Stackoverflow answer, it seems to be the same syntax as mine (the code just above).
So maybe this is an angular specific issue?
Here's the full error message I receive, when building with "ng serve" (on the angular cli):
ERROR in ./src/app/api-module/services/factory.service.ts Module not found: Error: Can't resolve '../sketch-objects' in 'D:\[...]\PhpStorm\vector-sketch\src\app\api-module\services' @ ./src/app/api-module/services/factory.service.ts 8:0-51
While having an import like the following works:
import {Scene} from '../sketch-objects/scene';
Just for understanding: I am programming an app which deals with threeJS, and want to create some sort of factory, which builds threeJS objects (or more precisely, a wrapper around a threeJS object) according to a specific string given in. For example I have a function// factory.service.ts import * as lib from './lib' ... create(objectType: string): any { let threeObject = lib[objectType](); return threeObject; }
I appreciate any help, Thanks.
bertiooo
原文:https://stackoverflow.com/questions/45118418
最满意答案
我使用了dplyr而不是你使用的summarySE函数
library(dplyr) test <- df %>% gather(., key="var", value="value", -x1, -x2) %>% group_by(x1,x2,var) %>% summarise(N=n(), Mean = mean(value), sd= sd(value), se = sd/sqrt(N), ci = qnorm(0.975)*se) %>% ungroup
下面的代码创建了一列由地点着色的条形图,并由变量分割。
test %>% ggplot(., aes(x=x2, y=Mean, fill=x1)) + geom_bar(position=position_dodge(), stat="identity") + geom_errorbar(aes(ymin=Mean-ci, ymax=Mean+ci), width=.2,position=position_dodge(.9)) + facet_wrap(~var, ncol = 1)
可能值得考虑使用箱形图,因为它们经常传达关于数据集的更多信息而不是条形图。
df %>% gather(., key="var", value="value", -x1, -x2) %>% ggplot(., aes(x=x2, y=value, fill=x1)) +geom_boxplot() + facet_wrap(~var, ncol = 1)
I have used dplyr instead of the summarySE function you used
library(dplyr) test <- df %>% gather(., key="var", value="value", -x1, -x2) %>% group_by(x1,x2,var) %>% summarise(N=n(), Mean = mean(value), sd= sd(value), se = sd/sqrt(N), ci = qnorm(0.975)*se) %>% ungroup
The below code creates a single column of bar plots coloured by site, and faceted by variable.
test %>% ggplot(., aes(x=x2, y=Mean, fill=x1)) + geom_bar(position=position_dodge(), stat="identity") + geom_errorbar(aes(ymin=Mean-ci, ymax=Mean+ci), width=.2,position=position_dodge(.9)) + facet_wrap(~var, ncol = 1)
It may be worth considering using a box plot as they often convey more information about the datset than bar plots.
df %>% gather(., key="var", value="value", -x1, -x2) %>% ggplot(., aes(x=x2, y=value, fill=x1)) +geom_boxplot() + facet_wrap(~var, ncol = 1)
相关问答
更多-
ggplot2警告:当ymin!= 0时堆叠不能很好地定义(ggplot2 warning: Stacking not well defined when ymin != 0)[2022-03-13]
1)通过将 position = "identity" 添加到geom_bar或当然,通过使用 suppressWarnings(print(ggplot(...))) 2-3)考虑到技术方面 - 是的,你可以忽略它。 此警告的原因与解释条形具有负高度而不仅仅是负值有关。 1) Either by adding position = "identity" to geom_bar or, of course, by using suppressWarnings(print(ggplot(...))) 2- ... -
在ggplot2上具有多个解释变量的模型的预测线(Predicted lines for model with multiple explanatory variables on ggplot2)[2023-06-06]
您可以将predict与多个解释变量一起使用,就像在上一个问题的答案中使用它一样。 然后,您只需将预测反向转换为原始比例。 预测是在不同的data.frame中,所以如果我使用ggplot我通常将绘图与原始data.frame映射并添加点,然后使用data.frame预测绘制线条。 # A transformed response df$resp2 = df$resp^(1/3.79) m2 = lm(resp2 ~ expl1 * expl2, data=df) plotexpl = seq(1, 4 ... -
这里有很多事情要做。 首先,在调用aes(...)使用外部变量是一个非常非常糟糕的主意。 aes(...)的参数在data=...参数的上下文中进行评估,因此在您的情况下是df的上下文中。 如果失败了,他们将在全球环境中进行评估。 所以最好做这样的事情: gg <- data.frame(x=df[[i]],y=df[[j]]) plots[[n]] = ggplot(data = gg, aes(x,y)) +... 其次, ggplot存储aes(...)的表达式 ,并在绘制情节时对其进行评估(因此, ...
-
好吧这是垃圾,但我能做的最好。 这是非常低效的,因为它通过lapply重新创建每个循环的部分数据。 也许别人有更好的东西: MAT <- outer(names(df)[-1], names(df)[-1], paste) combs <- sapply(MAT[lower.tri(MAT)], function(x) strsplit(x, " ")) ind <- lapply(combs, function(x) match(x, names(df))) plotter <- function(cn ...
-
我使用了dplyr而不是你使用的summarySE函数 library(dplyr) test <- df %>% gather(., key="var", value="value", -x1, -x2) %>% group_by(x1,x2,var) %>% summarise(N=n(), Mean = mean(value), sd= sd(valu ...
-
图使用ggplot2(Graphs using ggplot2)[2024-01-24]
library(ggplot2) dataa <- data.frame(Description =c("re","re1","re2") ,Condition=c("Obese","Fit","Slim"),RPKM=c(34,23,67)) ggplot(data=dataa,aes(x=Description, y=RPKM,fill=Condition))+ geom_bar(position="dodge",stat="identity")` 这就是我得 ... -
ggplot() + geom_bar(data=melted,aes(x=x,y=value,fill=variable), stat="identity",position = "identity", alpha=.3) + scale_fill_manual(values=c("#955599", "#E63F00")) 您现在可以使用调色板( - ; ggplot() + geom_bar(data=melted,aes(x=x,y=value,fill ...
-
Cgplot在ggplot2中绘制(Catepillar plots in ggplot2)[2022-01-07]
建立jebyrnes答案 - 您可以将y轴设置为在facet_wrap自由比例作为参数。 我们可以用geom_hline()添加一条水平线: ggplot(melt_df, aes(1:100, value)) + geom_point() + facet_wrap(~ variable, ncol = 3, scales = "free_y") + geom_hline(aes(intercept = 0), linetype = 2) + theme_bw(base_size ... -
R ggplot2:列不堆叠(R ggplot2: Columns not stacking)[2022-04-22]
试试这个: df <- rbind(cbind(z1, type=rownames(z1), data='z1'), cbind(z2, type=rownames(z2), data='z2')) ggplot(df, aes(type, total, fill=data)) + geom_bar(stat="identity") + scale_fill_manual(values=c(rgb(red=200, green=0, blue=50, maxColorValue = 255), r ... -
首先,更改了您的示例数据。 在创建数据框时,您不需要cbind()因为在这种情况下,您将所有列都作为因子。 foo <- data.frame(case=c('A','B','C'), var1=rnorm(3), var2=rnorm(3)) 为条形图使用两个变量最简单的方法是将数据从宽格式转换为长格式。 library(reshape2) foo.long<-melt(foo) foo.long case variable value 1 A var1 0.7150827 ...