我创建了NG-CLI(beta.15)一个新的项目并修改了app.component.spec改变beforeEach,以一个beforeAll和它造成的测试失败,出现以下错误:
失败:无法创建组件AppComponent,因为它未导入测试模块!
我不明白这个错误意味着什么,当然为什么我会在第一时间得到它.
这是修改后的规范:
import { TestBed, async } from '@angular/core/testing';
import { AppComponent } from './app.component';
describe('App: Ng2CliTest2', () => {
beforeAll(() => {
TestBed.configureTestingModule({
declarations: [
AppComponent
],
});
});
it('should create the app', async(() => {
let fixture = TestBed.createComponent(AppComponent);
let app = fixture.debugElement.componentInstance;
expect(app).toBeTruthy();
}));
it(`should have as title 'app works!'`, async(() => {
let fixture = TestBed.createComponent(AppComponent);
let app = fixture.debugElement.componentInstance;
expect(app.title).toEqual('app works!');
}));
it('should render title in a …Run Code Online (Sandbox Code Playgroud) 我只是在其中添加了一个包含SharedComponent的共享模块,并在主app组件中使用了该组件:
<acs-shared></acs-shared>
Run Code Online (Sandbox Code Playgroud)
所有组件都显示'Hello,world!' 在组件上使用属性:
<h1>Hello, {{name}}!</h1>
Run Code Online (Sandbox Code Playgroud)
在运行项目时npm start,这一切都正常,但现在运行npm test失败,也是如此$(npm bin)/karma start ./karma.conf.js.第一个失败是它无法创建组件,因为它无法识别'acs-shared'元素.是否有一些特殊的东西需要用来测试使用其他组件或模块的组件?
Chrome 54.0.2840 (Windows 10 0.0.0) App: AngularCliStarter should create the app FAILED
'acs-shared' is not a known element:
Run Code Online (Sandbox Code Playgroud)
该项目可在github上找到:https://github.com/JasonGoemaat/angular-cli-starter
我正在尝试使用Angular 2(使用最新的基于webpack的角度cli)为gui原型化一个Electron应用程序,但是因为我没有得到如何在我的angular2组件中导入Electron api而陷入困境.具体来说,我希望能够在点击ui中的按钮时打开一个新的BrowserWindow ...所以:
<button type="button" (click)="openNewWindow()">
open
</button>
Run Code Online (Sandbox Code Playgroud)
在我的组件中:
openNewWindow() {
let appWindow = new BrowserWindow({width: 800, height: 600});
appWindow.loadUrl('http://www.google.com');
}
Run Code Online (Sandbox Code Playgroud)
但是......如何导入BrowserWindow?!
通过使用:
import { BrowserWindow } from 'electron';
Run Code Online (Sandbox Code Playgroud)
我得到一个"没有模块错误",并按照这个问题的答案:Webpack找不到模块'电子'我得到:
syntax error near unexpected token ( var electron = require('./')
Run Code Online (Sandbox Code Playgroud)
我该怎么办?
PS.通过运行" electron ."而不BrowserWindow导入应用程序正常工作
是否可以异步生成环境对象?
原因:我希望在我的应用程序中有可用的提交哈希。想法是使用environment.ts文件。但是,要获取当前的提交哈希,我需要异步调用(例如,使用git-rev)。
我试图使用process.env从环境变量中注入变量: $ VERSION=123 ng serve
declare var process: any;
export const environment = {
production: false,
version: process.env.VERSION
};
Run Code Online (Sandbox Code Playgroud)
但这导致未定义的版本。
我正在使用"primeng":"^ 4.0.0-rc.2"和"@ angular/cli":"^ 1.0.0"和angular4.当我尝试使用对话框时,对话框无法访问 - 它隐藏在叠加层后面,应阻止访问页面的其余部分.请参见下图
我希望对话框可以点击,但手机用户界面是unlickagle.鳕鱼的片段如下所示:
<p-confirmDialog width = "425"
class = 'dialog-z-index'></p-confirmDialog>
Run Code Online (Sandbox Code Playgroud)
confirm() {
this._confirmationSrvc.confirm(
{
message: `Are you sure you want to delete the phone entry? ${
jsonStringify( this.deletionData )}`,
header: 'Delete Confirmation',
icon: 'fa fa-trash',
accept: () => {
}
} )
}
onDeleteConfirm( event ): void {
this.deletionData = event.data as IPhone
this.isDialog = true
if ( this.isDialog ) {
this.confirm()
event.confirm.resolve()
event.source.onChangedSource.subscribe(
changedSrc => {
if ( this.currentData.length < 1 ) { …Run Code Online (Sandbox Code Playgroud) 我正在使用一个新的angular-cli"my-project"并创建了一个简单的虚拟服务.我希望此服务连接到本地计算机上的laravel后端.我发现后端的Angular-CLI代理不起作用,但即使这些步骤对我来说也不起作用.Chrome仍然会访问localhost:4200.
我的服务
import { Injectable } from '@angular/core';
import {Http, Response} from '@angular/http';
@Injectable()
export class DummyService {
constructor(private http: Http) {
console.log('Hello dummyService');
}
getMessages() {
return this.http.get('/backend/public/api/auth/login').map((res: Response) => res.json());
}
}
Run Code Online (Sandbox Code Playgroud)
我的proxy.config.json
{
"/backend": {
"target": "http://localhost:81/laravelapi",
"secure": false,
"pathRewrite": {"^/backend" : ""},
"changeOrigin": true,
"logLevel": "debug"
}
}
Run Code Online (Sandbox Code Playgroud)
我的开始是package.json的开头
"start": "ng serve --proxy-config proxy.config.json",
Run Code Online (Sandbox Code Playgroud)
启动时,我得到以下日志消息:
** NG Live Development Server is running on http://localhost:4200 **
0% compiling
10% building modules 1/1 modules 0 active …Run Code Online (Sandbox Code Playgroud) 当我使用Angular 5 CLI生成一个新组件(例如ng gc my-component)时,它会创建4个文件(html,css,ts,spec.ts).我更愿意(或者代之以)为组件创建一个*.less文件.我不确定Angular存储用于生成新文件的文件列表或模板的位置.我可以添加自己要由CLI生成的文件类型吗?
当我试图通过终端使用命令在angular-cli中创建新项目时
Mani-MacBook-Air:angular-project manigupta$ ng new controlgame
Run Code Online (Sandbox Code Playgroud)
显示错误:
module.js:487
throw err;
^
Error: Cannot find module 'rxjs/operators'
at Function.Module._resolveFilename (module.js:485:15)
at Function.Module._load (module.js:437:25)
at Module.require (module.js:513:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/usr/local/lib/node_modules/@angular-devkit/core/src/logger/indent.js:10:21)
at Module._compile (module.js:569:30)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:503:32)
at tryModuleLoad (module.js:466:12)
at Function.Module._load (module.js:458:3)
Run Code Online (Sandbox Code Playgroud)
请让我知道在angular-cli中创建新项目应该怎么做
回答:
我卸载了angular-cli,然后使用以下命令安装最新版本
sudo npm uninstall -g @ angular/cli
npm缓存验证
sudo npm install -g @ angular/cli @ latest
('sudo'仅适用于mac/linux用户)
我看了一下新ng generate @angular/material:material-nav在这近角博客功能项.
不幸的是,当在一个全新的项目中运行以下CLI命令时,我收到一条错误消息(见下文).
ng add @angular/material
ng generate @angular/material:material-nav
Run Code Online (Sandbox Code Playgroud)
错误信息:
Schematic input does not validate against the Schema: {"dryRun":false,"inlineStyle":false,"inlineTemplate":false,"changeDetection":"Default","styleext":"css","spec":true,"flat":false,"skipImport":false,"export":false}
Errors:
Data path "" should have required property 'name'.
Run Code Online (Sandbox Code Playgroud)
这种糟透了.我尝试添加这样的名字
ng generate @angular/material:material-nav home
Run Code Online (Sandbox Code Playgroud)
但它仍然会产生相同的错误.请指教.
Angular CLI:6.0.0节点:8.11.1 OS:darwin x64 Angular:6.0.0
我想ng build --prod与WebStorm 一起运行,但是似乎只能这样做ng build并且错过了该--prod命令。
我想在WebStorm中而不是在终端中运行它。
注意:如果我添加--prod到Arguments,它将无法正常工作:
/usr/local/bin/node /usr/local/lib/node_modules/npm/bin/npm-cli.js run build --scripts-prepend-node-path=auto --prod
> cosmoline@0.0.0 build /Users/robertking/go/src/gitlab.com/cosmoline_client
> ng build
Run Code Online (Sandbox Code Playgroud)