生成新组件时,app.module.ts找不到新模块
When generating a new component, app.module.ts cannot find the new module
所以我遇到了一些困难 angular 6. 我会尽力解释:
我正在开发一个获得 MIT 许可的项目,它已经是一个非常可靠的基础项目。现在我已经按照我想要的方式设置了样式,我想生成一个新组件,我可以将其制作成用户可以填写的表单。
因此,我打开 CLI 和 ng g c FeeSchedule
,我可以看到 fee-schedule
组件已创建。我想在这一点上我应该能够编译并看到 运行ning <p> "fee-schedule works!" message <p>
如果我包含它的话。
生成组件后构建时出错:似乎是 TS-Lint 故障?
`System.InvalidOperationException: The NPM script 'serve' exited
without indicating that the Angular CLI was listening for requests.
The error output was: Lint errors found in the listed files.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! project@1.0.0 serve: ng lint && ng serve "--port" "6685"
npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the project@1.0.0
serve script. npm ERR! This is probably not a problem with npm. There
is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
---> System.IO.EndOfStreamException: Attempted to read past the end
of the stream. at
Microsoft.AspNetCore.SpaServices.AngularCli.AngularCliMiddleware.StartAngularCliServerAsync(String
sourcePath, String npmScriptName, ILogger logger) --- End of inner
exception stack trace --- at
Microsoft.AspNetCore.SpaServices.AngularCli.AngularCliMiddleware.StartAngularCliServerAsync(String
sourcePath, String npmScriptName, ILogger logger)`
知道为什么我 运行 在生成新组件时遇到问题吗?
我将尽可能多地包含相关代码:
import { NgModule } from "@angular/core";
import { BrowserModule } from "@angular/platform-browser";
import { RouterModule } from "@angular/router";
import { AppComponent } from "./app.component";
import { ROUTES } from "./app.routes";
import { LayoutModule } from "./views/layout/layout.module";
import { FeeScheduleComponent } from './views/fee-schedule/fee-schedule.component';
@NgModule({
bootstrap: [AppComponent],
declarations: [AppComponent, FeeScheduleComponent],
imports: [
BrowserModule,
RouterModule.forRoot(ROUTES),
LayoutModule
]
})
export class AppModule { }
和我的股票费用表组成部分:
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-fee-schedule',
templateUrl: './fee-schedule.component.html',
styleUrls: ['./fee-schedule.component.css']
})
export class FeeScheduleComponent implements OnInit {
constructor() { }
ngOnInit() {
}
}
我认为值得一提的是,即使我删除了 index.html 中的 app-fee-schedule 调用,应用程序仍然无法 运行。
附件是我的 ts lint 配置;
{
"extends": [ "tslint:latest" ],
"rulesDirectory": [ "node_modules/codelyzer" ],
"rules": {
"angular-whitespace": [ true, "check-interpolation", "check-pipe", "check-semicolon" ],
"banana-in-box": true,
"component-class-suffix": [ true, "Component" ],
"component-selector": [ true, "element", "app", "kebab-case" ],
"contextual-life-cycle": true,
"decorator-not-allowed": true,
"directive-class-suffix": [ true, "Directive" ],
"directive-selector": [ true, "attribute", "app", "camelCase" ],
"import-destructuring-spacing": true,
"indent": [ true, "tabs", 4 ],
"max-line-length": false,
"member-access": [ true, "no-public" ],
"no-attribute-parameter-decorator": true,
"no-console": false,
"no-empty": false,
"no-forward-ref": true,
"no-input-rename": true,
"no-output-named-after-standard-event": true,
"no-output-on-prefix": true,
"no-output-rename": true,
"no-submodule-imports": false,
"no-unused-css": true,
"no-var-requires": false,
"pipe-impure": true,
"pipe-naming": [ "camelCase", "Pipe" ],
"templates-no-negated-async": true,
"trailing-comma": false,
"use-host-property-decorator": true,
"use-input-property-decorator": true,
"use-life-cycle-interface": true,
"use-output-property-decorator": true,
"use-pipe-decorator": true,
"use-pipe-transform-interface": true,
"use-view-encapsulation": true
}
}
SO:问题是我这一代人在默认情况下将组件导入 App.module.ts,而我想在特定组件中使用它。我对 App.Module 运作方式的理解是错误的。
感谢所有指点,我想我只是在问我的问题时没有足够深入地解释我的代码。
所以我遇到了一些困难 angular 6. 我会尽力解释:
我正在开发一个获得 MIT 许可的项目,它已经是一个非常可靠的基础项目。现在我已经按照我想要的方式设置了样式,我想生成一个新组件,我可以将其制作成用户可以填写的表单。
因此,我打开 CLI 和 ng g c FeeSchedule
,我可以看到 fee-schedule
组件已创建。我想在这一点上我应该能够编译并看到 运行ning <p> "fee-schedule works!" message <p>
如果我包含它的话。
生成组件后构建时出错:似乎是 TS-Lint 故障?
`System.InvalidOperationException: The NPM script 'serve' exited without indicating that the Angular CLI was listening for requests. The error output was: Lint errors found in the listed files.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! project@1.0.0 serve:
ng lint && ng serve "--port" "6685"
npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the project@1.0.0 serve script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above.npm ERR! A complete log of this run can be found in:
---> System.IO.EndOfStreamException: Attempted to read past the end of the stream. at Microsoft.AspNetCore.SpaServices.AngularCli.AngularCliMiddleware.StartAngularCliServerAsync(String sourcePath, String npmScriptName, ILogger logger) --- End of inner exception stack trace --- at Microsoft.AspNetCore.SpaServices.AngularCli.AngularCliMiddleware.StartAngularCliServerAsync(String sourcePath, String npmScriptName, ILogger logger)`
知道为什么我 运行 在生成新组件时遇到问题吗?
我将尽可能多地包含相关代码:
import { NgModule } from "@angular/core";
import { BrowserModule } from "@angular/platform-browser";
import { RouterModule } from "@angular/router";
import { AppComponent } from "./app.component";
import { ROUTES } from "./app.routes";
import { LayoutModule } from "./views/layout/layout.module";
import { FeeScheduleComponent } from './views/fee-schedule/fee-schedule.component';
@NgModule({
bootstrap: [AppComponent],
declarations: [AppComponent, FeeScheduleComponent],
imports: [
BrowserModule,
RouterModule.forRoot(ROUTES),
LayoutModule
]
})
export class AppModule { }
和我的股票费用表组成部分:
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-fee-schedule',
templateUrl: './fee-schedule.component.html',
styleUrls: ['./fee-schedule.component.css']
})
export class FeeScheduleComponent implements OnInit {
constructor() { }
ngOnInit() {
}
}
我认为值得一提的是,即使我删除了 index.html 中的 app-fee-schedule 调用,应用程序仍然无法 运行。
附件是我的 ts lint 配置;
{
"extends": [ "tslint:latest" ],
"rulesDirectory": [ "node_modules/codelyzer" ],
"rules": {
"angular-whitespace": [ true, "check-interpolation", "check-pipe", "check-semicolon" ],
"banana-in-box": true,
"component-class-suffix": [ true, "Component" ],
"component-selector": [ true, "element", "app", "kebab-case" ],
"contextual-life-cycle": true,
"decorator-not-allowed": true,
"directive-class-suffix": [ true, "Directive" ],
"directive-selector": [ true, "attribute", "app", "camelCase" ],
"import-destructuring-spacing": true,
"indent": [ true, "tabs", 4 ],
"max-line-length": false,
"member-access": [ true, "no-public" ],
"no-attribute-parameter-decorator": true,
"no-console": false,
"no-empty": false,
"no-forward-ref": true,
"no-input-rename": true,
"no-output-named-after-standard-event": true,
"no-output-on-prefix": true,
"no-output-rename": true,
"no-submodule-imports": false,
"no-unused-css": true,
"no-var-requires": false,
"pipe-impure": true,
"pipe-naming": [ "camelCase", "Pipe" ],
"templates-no-negated-async": true,
"trailing-comma": false,
"use-host-property-decorator": true,
"use-input-property-decorator": true,
"use-life-cycle-interface": true,
"use-output-property-decorator": true,
"use-pipe-decorator": true,
"use-pipe-transform-interface": true,
"use-view-encapsulation": true
}
}
SO:问题是我这一代人在默认情况下将组件导入 App.module.ts,而我想在特定组件中使用它。我对 App.Module 运作方式的理解是错误的。 感谢所有指点,我想我只是在问我的问题时没有足够深入地解释我的代码。