我按照 ng2-charts 演示页面上的说明进行设置。我正在使用 angular-cli,所以我也使用 System.JS 导入了包。然后我复制了演示代码,但它不会显示。正在创建画布,但没有绘制图表。我的组件和模板代码与此处完全相同。
有没有办法在构建时评估某些内容,然后在 angular-cli 构建过程中将其添加到应用程序中?
用例:
我之前用 gulp 构建了一个应用程序。您可以执行以下操作:
git rev-parse --short HEAD
Run Code Online (Sandbox Code Playgroud)
然后,您可以使用gulp-replace将其添加到应用程序中:
const GIT_VERSION = "{GIT_VERSION}";
Run Code Online (Sandbox Code Playgroud)
最后,编译后的应用程序将如下所示:
const GIT_VERSION = "59e5722";
Run Code Online (Sandbox Code Playgroud)
angular-cli 是否提供了一些东西来实现这一点而不必恢复到 gulp?
我想编写一个组件,它基本上根据其输入显示不同的图标。图标框架期望它采用以下格式:
<span class="icon icon-generic" data-icon="B"></span>
Run Code Online (Sandbox Code Playgroud)
所以data-icon="B"基本上描述了显示哪个图标。我想动态传递这个符号。就像是:
<span class="icon icon-generic" data-icon={{symbol}}></span>
Run Code Online (Sandbox Code Playgroud)
但这似乎行不通。:-/ 有没有办法做到这一点,而无需在我的 Component 类中创建 html 并将其附加到 html 中?
是否有任何配置设置可以删除这些空注释和空格?
我的构建命令ng build --environment prod --progress false --target production和 tsconfig 是:
{
"compileOnSave": false,
"compilerOptions": {
"alwaysStrict": true,
"baseUrl": "/",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"forceConsistentCasingInFileNames": true,
"lib": [ "es2015", "dom" ],
"module": "es2015",
"moduleResolution": "node",
"newLine": "CRLF",
"noFallthroughCasesInSwitch": true,
"noImplicitAny": true,
"noImplicitReturns": true,
"noUnusedLocals": true,
"noUnusedParameters": false,
"outDir": "./dist/out-tsc",
"removeComments": true,
"skipDefaultLibCheck": true,
"skipLibCheck": true,
"strictNullChecks": true,
"target": "es5",
"typeRoots": [ "./node_modules/@types" ]
}
}
Run Code Online (Sandbox Code Playgroud)
@angular/cli:1.0.4
节点:7.2.1
操作系统:win32 x64
@angular/common:4.1.3
谢谢你。
我正在尝试创建一个脚本来运行端到端测试套件。我目前正在同时使用 angular cli,如下所示:
"e2e": "concurrently \"ng e2e --proxy-config proxy.conf.json\" \"cross-env NODE_ENV=development node server\"",
Run Code Online (Sandbox Code Playgroud)
它运行良好,但我的问题是,显然当ng e2e命令完成时,我的后端服务器没有。测试完成后,有没有办法让整个命令完成?
该项目是通过有角度的CLI生成的。我具有以下文件夹结构:
我想定义的路径栏文件夹tsconfig.app.json和进口Car到Garage。
我的tsconfig.app.json:
{
"extends": "../tsconfig.json",
"compilerOptions": {
...
"baseUrl": "./",
"paths" : {
"@bar" : ["foo/bar"]
},
...
},
...
}
Run Code Online (Sandbox Code Playgroud)
我的Garage.ts:
import { Car } from "@bar/Car";
export class Garage {}
Run Code Online (Sandbox Code Playgroud)
在garage.ts中,我有一个错误:
找不到模块“ @ bar / car”。
将值从父级传递给子级.子组件中接收的值是未定义的工作示例
这是我的app.component
import { Component, OnInit } from '@angular/core';
import {HttpClient} from '@angular/common/http';
interface ItemsResponse {
data: any[];
}
@Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: [ './app.component.css' ]
})
export class AppComponent implements OnInit {
constructor(private http: HttpClient) {}
ngOnInit() {
this.getPosts();
console.log( this.name); // name is undefined
}
name;
results:Array<any> = []; // code changed
getPosts() {
this.http.get<ItemsResponse>('https://reqres.in/api/users?page=3').subscribe(res =>
this.name = res); // code changed
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的hello组件,其中数据被传递给子组件您可以看到在构造函数中未定义通过angular的@input装饰器从父组件传递到子组件的名称.
import { Component, Input } from '@angular/core';
@Component({
selector: 'hello', …Run Code Online (Sandbox Code Playgroud) 我正在开发一个角度应用程序,它是一个产品并部署到多个客户端.客户端将采用此角度应用程序并将其托管在其服务器中.因此,服务的网址对于客户来说会有所不同.我见过关于dev,prod的解决方案.但这不适用于这种情况.我正在寻找类似于.net配置文件的配置文件.我创建了一个单独的app.config.ts文件,但是在构建时会生成该文件.我正在寻找一个解决方案,我可以将应用程序部署到任何客户端,而不是再次构建它.
import { InjectionToken } from "@angular/core";
export let APP_CONFIG = new InjectionToken("app.config");
export interface IAppConfig {
apiEndpoint: string;
}
export const AppConfig: IAppConfig = {
apiEndpoint: "http://88.87.86.999/"
};
Run Code Online (Sandbox Code Playgroud) 我有一个现有的项目,我想使用Angular CLI添加一个Angular应用程序.
项目结构现在看起来像这样:
客户端和共享文件夹仍然是空的,我想在客户端文件夹中安装我的角度应用程序,但我仍然想为整个项目维护一个package.json.这就是我尝试使用以下内容添加angular-cli.json的原因:
{
"project": {
"name": "projectname"
},
"apps": [
{
"root": "./src/client",
"outDir": "./dist/browser"
}
]
}
Run Code Online (Sandbox Code Playgroud)
问题:
现在将Angular应用程序(到/ src/client)添加到我的项目的最佳方法是什么?ng new由于现有的package.json,我无法简单地运行,也许它不会在/ src/client文件夹中生成应用程序.
我的应用程序中有一些浏览器动画,它们运行正常,没有错误。ng test即使我BrowserAnimationsModule在app.module.ts文件中包含,我运行时也会遇到此错误。我正在使用动画HeaderComponent
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';
import { HeaderComponent } from './header/header.component';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { registerLocaleData } from '@angular/common';
import localeEs from '@angular/common/locales/es';
registerLocaleData(localeEs, 'es-us')
@NgModule({
declarations: [
AppComponent,
HeaderComponent
],
imports: [
BrowserModule,
BrowserAnimationsModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
Run Code Online (Sandbox Code Playgroud)
我已经尝试过此解决方案,但仍然遇到相同的问题。
angular-cli ×10
angular ×9
angular5 ×2
tsconfig ×2
typescript ×2
e2e-testing ×1
gulp ×1
html ×1
import ×1
ng2-charts ×1
npm-scripts ×1
unit-testing ×1