当ng serve在命令行中运行angular-cli生成的项目时,我收到以下错误:
ERROR in Cannot read property 'listLazyRoutes' of undefined
Run Code Online (Sandbox Code Playgroud)
有关如何修复此错误的任何想法?
我正在运行以下命令进行单元测试并生成代码覆盖率报告.
ng test --code-coverage
Run Code Online (Sandbox Code Playgroud)
它工作正常并在coverage文件夹中编写代码覆盖率报告.
在这里我得到了所有文件和目录覆盖率报告
但是我想排除特定的文件/目录src/app/quote/services/generated.怎么做?
我认为在Angular-cli树抖动中排除组件的问题非常相似,但我似乎无法从中得到任何东西.
基本上我有一个动态组件工厂,如我如何使用/创建动态模板来编译动态组件与Angular 2.0?.
当我使用最新的Angular CLI和非生产设置构建它时,一切正常.但是,一旦我使用生产设置,我在尝试加载具有动态创建内容的页面时立即在浏览器中获得以下错误跟踪:
例外:找不到'e'的NgModule元数据.
ORIGINAL STACKTRACE:
main.dc05ae9 ... .bundle.js:格式:4731
错误:找不到'e'的NgModule元数据.
at t(vendor.c18e6df ... .bundle.js:格式化:76051)
at t.resolve(vendor.c18e6df ... .bundle.js:格式化:20624)
at t.getNgModuleMetadata(vendor.c18e6df ... .bundle.js:formatted: 20169)
在t._compileModuleAndAllComponents(vendor.c18e6df ... .bundle.js:格式化:40462)的t._loadModules(vendor.c18e6df ... .bundle.js:格式化:40474
)
at t.compileModuleAndAllComponentsSync(vendor.c18e6df ... .bundle. js:格式化:40436)
在e.createComponentFactory(main.dc05ae9 ... .bundle.js:格式:4789)
这是我的组件工厂类:
@Injectable()
export class DynamicTypeBuilder {
constructor() {
}
private _cacheOfFactories: {[templateKey: string]: ComponentFactory<any>} = {};
private compiler: Compiler = new JitCompilerFactory([{useDebug: false, useJit: true}]).createCompiler();
public createComponentFactory<COMPONENT_TYPE>(type: any, template: string, additionalModules: any[] = []): Observable<ComponentFactory<COMPONENT_TYPE>> {
let …Run Code Online (Sandbox Code Playgroud) 我使用Visual Studio 2017构建了一个Angular-CLI .Net Core SPA
dotnet new angular -o my-new-app
Run Code Online (Sandbox Code Playgroud)
我正在努力寻找的是在写入时默认调用文件夹index.html内部的内容ClientApp/src
http://localhost:57782
Run Code Online (Sandbox Code Playgroud)
startup.cs文件如下:
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.SpaServices.AngularCli;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
namespace angular_cli
{
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
//services.AddMvc();
// In production, the Angular files will be …Run Code Online (Sandbox Code Playgroud) 我们应该像下面的代码一样在index.html文件中包含字体,rel="preload"还是我们可以在 Angular CLI 中配置它来预加载所有需要的字体?
请建议我一个更好的解决方案,因为我可以看到 Google 分析中建议的页面加载时间需要多秒。
<link rel="preload" href="./assets/fonts/Lato/Lato-Semibold.woff2" as="font" crossorigin>
<link rel="preload" href="./assets/fonts/Lato/Lato-Black.woff2" as="font" crossorigin>
<link rel="preload" href="./assets/fonts/Lato/Lato-Bold.woff2" as="font" crossorigin>
<link rel="preload" href="./assets/fonts/Lato/Lato-Heavy.woff2" as="font" crossorigin>
<link rel="preload" href="./assets/fonts/Lato/Lato-Medium.woff2" as="font" crossorigin>
<link rel="preload" href="./assets/fonts/Lato/Lato-Regular.woff2" as="font" crossorigin>
Run Code Online (Sandbox Code Playgroud) 目前尚未安装"ng"程序.您可以通过键入以下命令安装它:sudo apt install ng-common
我在安装过程中没有错误,我该如何解决?
编辑:当我尝试运行时会发生这种情况 ng new PROJECT_NAME
我想安装的最新版本NodeJS上Ubuntu Zesty 17.04.但无论是使用apt-get还是尝试从nodesource ppa下载它,我总是拥有版本4.7.2.
apt-get的
sudo apt-get update
sudo apt-get install nodejs npm
Run Code Online (Sandbox Code Playgroud)
节点PPA
curl -sL https://deb.nodesource.com/setup_6.x | sudo bash -
sudo apt-get update
apt-get install nodejs npm
Run Code Online (Sandbox Code Playgroud)
结果
$> node -v
v4.7.2
Run Code Online (Sandbox Code Playgroud)
我怎样才能获得NodeJS的6.9版本?
我正在使用Rxjs中的angualr-cli应用程序.
在viewer.component.ts中
//Other Imports
import { Observable } from 'rxjs/Observable';
//omitting for brevity
export class ViewerComponent implements OnInit, AfterViewInit, OnDestroy {
someFunction(someArg){
//omitting for brevity
let someArray: any = [];
//Add some info
Observable.forkJoin(someArray).subscribe(data => {
//Do something with data
});
}
//omitting for brevity
}
Run Code Online (Sandbox Code Playgroud)
我得到了错误
ERROR TypeError: __WEBPACK_IMPORTED_MODULE_2_rxjs_Observable__.Observable.forkJoin is not a function
at ViewerComponent.webpackJsonp../src/app/component/viewer.component.ts.ViewerComponent.someFunction(http://localhost:4200/main.bundle.js:4022:73)
at http://localhost:4200/main.bundle.js:3951:31
Run Code Online (Sandbox Code Playgroud)
但如果我Rxjs完全导入(import 'rxjs';)一切正常.没错.我似乎还明白了什么是必要的.我也尝试导入rxjs/Observable/forkjoin但没有任何可用的.
关于如何解决这个问题的任何指示.
我为一个组件创建了一系列单元测试.它最初失败了,因为我得到了上述错误,所以我拿出了event.defaultPrevented的东西,却没有真正知道它在做什么.
好吧,这修复了我的错误,但显然对UI行为产生了非常糟糕的副作用,所以我不得不把这些东西放回我的代码中.
所以,现在我回来修复我的单元测试.我怎样才能将事件内容模拟/注入我的单元测试中?
只是由Angular CLI删除的默认"应该创建"测试失败,这里是代码:
let component: MemberAddComponent;
let fixture: ComponentFixture<MemberAddComponent>;
let contractsService: ContractsService;
let notesService: NotesService;
let saveButton: any;
beforeEach(async(() => {
let router = { navigate: jasmine.createSpy('navigate') };
TestBed.configureTestingModule({
imports: [
HttpModule,
FormsModule,
ReactiveFormsModule,
RouterTestingModule
],
declarations: [
MemberAddComponent,
// lots more here
],
providers: [
AppDataService,
ErrorService,
{
provide: ContractsService,
useClass: MockContractsService
},
{
provide: NotesService,
useClass: MockNotesService
}
]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(MemberAddComponent);
component = fixture.componentInstance;
contractsService = fixture.debugElement.injector.get(ContractsService);
saveButton = …Run Code Online (Sandbox Code Playgroud) 我正在使用angular-fontawesome和datatables,我想在表格中创建一个按钮,但我想用fontawesome来放置一个图标而不是文本.我有以下代码:
this.dtOptions = {
//...
buttons: [
//...
{
extend: 'pdf',
text: '<fa-icon [icon]="faDownload"></fa-icon>'
}
]
};
Run Code Online (Sandbox Code Playgroud)
我知道我不会以这种方式加载图标的组件,但有没有办法在不必使用fontawesome css的情况下完成它?
angular-cli ×10
angular ×8
asp.net ×1
asp.net-core ×1
asp.net-mvc ×1
datatables ×1
font-awesome ×1
fonts ×1
fork-join ×1
html ×1
istanbul ×1
jasmine ×1
javascript ×1
karma-runner ×1
node.js ×1
npm ×1
preload ×1
rxjs5 ×1
tree-shaking ×1
ubuntu ×1
unit-testing ×1
webpack ×1