![](/img/trans.png)
[英]How to pass data from app.component.ts to its app.module.ts in Angular?
[英]ModuleNotFoundError (Could not find module in path: './translate.service' relative to '/src/app/app.component.ts')
我是 angular 的新手,想构建一个翻译应用程序,但遇到了这个错误。 代码如下:
import { Component } from "@angular/core";
import { TranslateService } from "./translate.service";
@Component({
selector: "app-root",
templateUrl: "./app.component.html",
styleUrls: ["./app.component.css"]
})
export class AppComponent {
text: string;
translatedText: string;
constructor(private translateService: TranslateService) {};
submit(){
this.translateService.translate(this.text).subscribe((result)=>{
this.translatedText = result;
})
}
}
您必须在“导入”列表中的 app.module.ts 中导入TranslateModule 。 在官方文档中,您可以找到您需要的任何其他信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.