- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个用 Typescript 编写的相当大的 AngularJS(又名 Angular 1)应用程序。我决定应使用 Angular(又名 Angular 4)编写新功能,并采取措施以“混合模式”增强应用程序。
这似乎有效(所有 AngularJS 位都工作正常),并且我添加了一个 Angular 组件并且渲染良好。
当我尝试将 Angular 服务添加到我的 Angular 中时(到目前为止都是 Angular 4),问题就出现了。 Angular 无法工作,吐出了看似无处不在的内容无法解析所有参数...错误。
但是,如果我用 @Inject 标记组件构造函数中的类型,那么它就可以正常工作。
所有文档都指出我不需要定期使用 @Inject,那么为什么会失败?
我的中期需求是将 AngularJS 服务注入(inject)到 Angular 组件和服务中,但这种情况并没有让我充满信心。
app.module.ts:
// All AngualarJS definitions appear before this section.
@NgModule({
imports: [
BrowserModule,
UpgradeModule,
],
declarations: [
AppComponent,
OrgSummaryComponent
],
providers: [
OrgDetailsService,
],
bootstrap: [
AppComponent,
],
})
export class AppModule {
ngDoBootstrap() {
// Does nothing by design.
// This is to facilitate "hybrid bootstrapping"
}
}
platformBrowserDynamic().bootstrapModule(AppModule).then(platformRef => {
const upgrade = platformRef.injector.get(UpgradeModule) as UpgradeModule;
upgrade.bootstrap(document.body, [AppModuleName], {strictDi: true});
});
org-details.service.ts:
import {Injectable} from "@angular/core";
export class OrgDetails {
public orgName: string;
}
@Injectable()
export class OrgDetailsService {
getOrgDetails () : OrgDetails {
const od = new OrgDetails();
od.orgName = "Some Org Name from a REST service";
return od;
}
}
org-summary.component.ts:
import {Component, Inject, OnInit} from "@angular/core";
import {OrgDetailsService} from "./org-details.service";
@Component ({
selector: "orgsummary",
template: "<h2>{{OrgName}}</h2>",
})
export class OrgSummaryComponent implements OnInit {
constructor (
/*@Inject(OrgDetailsService)*/ private orgs: OrgDetailsService, // Only works if I uncomment the @Inject
) {
}
public OrgName: string;
ngOnInit(): void {
this.OrgName = `${this.orgs.getOrgDetails().orgName}`;
}
}
tsconfig.json:
{
"compilerOptions": {
"module": "commonjs",
"target": "es6",
"sourceMap": true,
"noImplicitAny": true,
"declaration": true,
"experimentalDecorators": true
},
"exclude": [
"node_modules",
"**/*.spec.ts"
],
"include" : [
"app/**/*.ts"
]
}
非常感谢,杰夫
最佳答案
只需添加
"emitDecoratorMetadata": true
到您的tsconfig.json
关于javascript - 混合升压应用中的 Angular DI,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43847117/
在 Java 中,我可以在不指定类型的情况下定义泛型类的变量。 class Tree> {} somewhere-else: Tree tree; 然后我可以从文件中读入一些对象并将其类型转换为我想要
我昨天发布了一个问题,我使用 multi_map 解决了这个问题: Having a composite key for hash map in c++ 这很有效,但是当数据足够大时就会出现问题。 我
这应该很简单(我只是在学习 boost,所以我错过了一些东西) 我已经使用 json_read 读取了一些简单的 JSON,现在有了一个 ptree。网络上的所有示例都显示使用 ptree.get("
所以我的问题很简单,在我的词法分析器类(扩展 lex::lexer )中,我有以下内容; this->self.add ... ("&&", AND_AND) ("||", O
关于这个问题有很多问题,但似乎没有一个能解决我的问题。我不认为这真的是一个 Boost::Variant 问题;我很确定我只是以错误的方式使用了模板。我能够剥离代码,以便您可以编译它并自己查看问题,这
这个问题确定不可复制类型不能与 Boost Variant 一起使用 树类 template class Tree{ private: class TreeNode{
我有一个用于解析标识符的解析器,如 foo, bar, baz 和一个用于解析嵌套标识符的解析器,如 foo::bar, foo::bar.baz, foo::bar.baz.baham它们都解析为相
通过阅读其他 Stack Overflow 条目和 boost::asio 文档,我确认没有同步 ASIO 读/写调用也提供易于使用的超时作为调用的参数。 我正在使用使用超时的 select(2) 调
我应该在我的 jamroot.jam 文件中放入什么,以便 libAPLibrary.so 与 MyProject 编译的结果相关联? root |-MyProject | |-jamroot
我有一个 vector,我想将其插入到一个 set 中。这是三个不同的调用之一(另外两个更复杂,涉及 boost::lambda::if_()),但解决这个简单的案例将帮助我解决其他问题。 std::
我确定套接字在我的应用程序中的任何地方都关闭了,并且我不断在我的/proc/pid/fd/下获取这个新创建的 fd/socket 文件,这是正常的。我确定不是。 connection.cpp con
元组是由括号括起来的逗号分隔列表,例如 () (,) (thing,) (2,3) 如果我有 #define ISTUPLE(x) \\... 我想要类似 ISTUPLE(nope) 的东西解析为 0
我有一个问题,两个线程是这样调用的,一个接一个。 new boost::thread( &SERVER::start_receive, this); new boost::thread( &SERVE
遇到 Boost 程序选项问题。我添加了一个多次使用选项,我们称之为“--opt”。当我从命令行使用两个“--opt”运行program.exe时,我从boost中收到以下错误。 terminatin
我想用类似于 C 的转义规则来解析字符串。我想保留转义,而不是解码它们然后重新编码。所以我认为 *(char_('\\') >> char_ | char_ - '"') 会做我想做的事,但事实并非如
聊天程序就是一个很好的例子。只需要一个可以接受来自客户端的多个连接的服务器,并且该服务器需要能够向各个客户端发送消息。 我计划将它变成一个分布式计算程序,以使用多个神经网络。 最佳答案 Asio是处理
我是一名优秀的程序员,十分优秀!