目前尚未安装"ng"程序.您可以通过键入以下命令安装它:sudo apt install ng-common
我在安装过程中没有错误,我该如何解决?
编辑:当我尝试运行时会发生这种情况 ng new PROJECT_NAME
如何ng e2e使用配置文件为命令设置端口和主机?
我知道可以在命令行中使用以下语句
ng e2e --port <port number> --host <host>
Run Code Online (Sandbox Code Playgroud)
这很好用,但在配置文件中设置端口和地址会更方便.我已经查看了内部.angular-cli.json,发现有一个文件被调用protractor.config.js,我无法弄清楚在该文件中使用的baseUrl设置,有一个设置,但是更改它对使用的端口没有任何影响ng e2e命令.它似乎使用随机端口.
除了baseUrl我也试过设置port,seleniumPort但他们没有任何区别.
输入ng e2e命令后,控制台中将显示以下输出
** NG Live Development Server is running on http://localhost:49155 **
Run Code Online (Sandbox Code Playgroud)
在protractor.config.js我已经baseUrl设定为http://localhost:50000.我观察到测试正在执行,我可以看到浏览器使用的地址http://localhost:49155不是我想要的地址.
ng --version 返回以下内容
@ angular/cli:1.0.0
节点:7.7.1
os:win32 x64
@ angular/common:4.0.3
@ angular/compiler:4.0.3
@ angular/core:4.0.3
@ angular/forms:4.0.3
@ angular/http:4.0.3
@ angular/platform-browser:4.0.3
@ angular/platform-browser-dynamic:4.0.3
@ angular/router:4.0.3
@ angular/cli:1.0.0
@ angular/compiler- …
如何在我的 proxy.conf.json 中定义多个代理路径?github 上的angular-cli 代理文档看起来只能有一个路径 (/api):
{
"/api": {
"target": "http://localhost:3000",
"secure": false
}
}
Run Code Online (Sandbox Code Playgroud)
但是当我查看webpack 代理或http-proxy-middleware文档时,我发现应该可以定义多个路径(/api-v1 和 /api-v2):
// Multiple entry
proxy: [
{
context: ['/api-v1/**', '/api-v2/**'],
target: 'https://other-server.example.com',
secure: false
}
]
Run Code Online (Sandbox Code Playgroud)
但我不明白如何将其放入 proxy.conf.json。
webpack-dev-server angular-cli http-proxy-middleware angular
我正在使用Angular4和开始我的第一个项目,sass并且我正试图弄清楚如何以sass正确的方式工作.我正在使用angular-cli并已设置默认样式以使用scss语法.我也已经定义了编译等.
但是我看到组件上有一个选项styleUrls,在某些情况下我们定义仅在该组件中使用的样式.
问题是,当我设置一个scss文件时,component它不会生成它自己的.css文件,既不包含在主.css文件中,而是从根项目生成的.
所以基本上我有一个像这样的项目结构:
app
app.module.ts
app.routing.ts
home
home.component.ts
home.html
_home.scss
client
client.component.ts
client.html
_client.scss
scss
_imports.scss
colors
_colors.scss
ui
_button.scss
_table.scss
//.. more folder and files
styles.scss
index.html
Run Code Online (Sandbox Code Playgroud)
我希望能够css在styles.scss文件中设置主要样式,index.html稍后将在构建过程中将其插入到文件中.但也能够生成一个单一的css每个组件我有,如文件home和client,并且只使用那些css自己份内的风格component.
有可能吗?我试过这个,我没有找到任何关于此的其他资源!
我正在使用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) 我在我的项目中使用了插件ngx-leaflet和angular-cli.
我正在尝试使用文档中描述的传单,例如:
问题是当我尝试编译时出现以下错误:
编译:
ng serve --aot
Run Code Online (Sandbox Code Playgroud)
上下文:
我确实尝试L使用以下方式导入:
import { LeafletModule } from '@asymmetrik/ngx-leaflet';
但我在文档和github中找不到任何东西.
我确实删除了模块atm进行编译,但我需要一个解决方法.
这是package.json我使用的:
这是我的组件内部的代码,用户'L':
@Component({
selector: 'app-map-screens-element',
templateUrl: './map-screens-element.component.html',
styleUrls: [
'./map-screens-element.component.scss',
],
})
export class MapScreensComponent implements OnInit {
/**
* setting map options
*/
public $mapOptions = {
// we use the layer openstreetmap
layers: [
L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png'),
],
zoom: 15,
center: L.latLng([48.866667, 2.333333]),
};
}
Run Code Online (Sandbox Code Playgroud)
这里将模块导入我的项目:
import { LeafletModule } from …Run Code Online (Sandbox Code Playgroud) 当我的cordova应用程序试图在我的智能手机上运行时,我遇到了这个问题.
我正在使用角度cli.我搜索了指定的错误,我发现在github上是一个封闭的问题,解决方案(对许多人有用)是将.angular-cli.json中列出的资产放在一个数组中.关键是我的资产已经在一个数组中.我试图进一步看,但这个问题是我发现的唯一问题.
但是,编译webpacks是成功的,而不是错误.唯一的错误出现在浏览器中并且是标题的错误.
我不知道该怎么做.
我正在使用angular-fontawesome和datatables,我想在表格中创建一个按钮,但我想用fontawesome来放置一个图标而不是文本.我有以下代码:
this.dtOptions = {
//...
buttons: [
//...
{
extend: 'pdf',
text: '<fa-icon [icon]="faDownload"></fa-icon>'
}
]
};
Run Code Online (Sandbox Code Playgroud)
我知道我不会以这种方式加载图标的组件,但有没有办法在不必使用fontawesome css的情况下完成它?
将 node.js 和 npm 更新为当前 LTS 后:
node -v
v12.16.0
Run Code Online (Sandbox Code Playgroud)
npm -v
6.13.4
Run Code Online (Sandbox Code Playgroud)
当我尝试按照文档中的步骤安装 @angular-cli 时,
在终端中运行会停止安装,控制台输出为:npm install -g @angular/cli
npm install -g @angular/cli
npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
/Users/user/.npm-global/bin/ng -> /USERS/USER/.npm-global/lib/node_modules/@angular/cli/bin/ng
> @angular/cli@9.0.2 postinstall /USERS/USER/.npm-global/lib/node_modules/@angular/cli
> node ./bin/postinstall/script.js
+ @angular/cli@9.0.2
updated 1 package in 12.202s
Run Code Online (Sandbox Code Playgroud)
在这种情况下,ng new project-name产量-bash: ng: command not found。任何帮助都会非常受欢迎,因为我有一个大项目即将到来。谢谢大家。
angular-cli ×10
angular ×9
android ×1
cordova ×1
css ×1
datatables ×1
font-awesome ×1
fork-join ×1
jasmine ×1
javascript ×1
ngx-leaflet ×1
node.js ×1
npm ×1
npm-install ×1
protractor ×1
rxjs5 ×1
sass ×1
typescript ×1
unit-testing ×1
webpack ×1