我正在使用 angular 6 和 ng-bootstrap。我想改变背景颜色<ngb-tabset type="pills">
.nav-fill .nav-link.active {
margin-top: -1px;
border-top: 2px solid #20a8d8;
}
.nav-pills .nav-link.active, .nav-pills .show > .nav-link {
color: #fff;
background-color: #20a8d8;
}
Run Code Online (Sandbox Code Playgroud)
component.scss即使我使用!important这些是内联样式,我也无法覆盖它们。我不知道它们位于何处,搜索了整个项目都找不到它们。
我是 angular6 的新手,我有疑问。如何将数据从 ngFor 传递给 ng-template?
组件.html
<tr *ngFor="let user of data">
<td>{{user.id}}</td>
<td>{{user.username}}</td>
<td>{{user.surname}}</td>
<td>{{user.name}}</td>
<td>{{user.email}}</td>
<td>{{user.joinedAt | date:'dd-MM-yyyy HH:mm'}}</td>
<td *ngFor="let roles of user.roles">{{roles.name}}</td>
<td><button class="btn-dark" (click)="open(content)">EDIT</button></td>
</tr>
<ng-template #content let-c="close" let-d="dismiss">
//cant pass data there
</ng-template>
Run Code Online (Sandbox Code Playgroud)
组件.ts
export class Component implements OnInit {
public data: any;
constructor(private userService: UserService, private modalService: NgbModal) {
}
ngOnInit() {
this.getListUsers();
}
getListUsers() {
this.userService.getAll().subscribe(
restItems => {
this.data = restItems;
}
);
}
open(content) {
this.modalService.open(content, {ariaLabelledBy: 'modal-basic-title'});
}
} …Run Code Online (Sandbox Code Playgroud) 有一个使用环境变量的 angular 6 项目 ./project/src/environments/environment.prod.ts
export const environment = {
production: true,
testVar: 'gg',
};
Run Code Online (Sandbox Code Playgroud)
这个项目的后端在一个.env文件中也有 env 变量,所以很多变量重复了 angular env 变量。有类似的东西会很好
export const environment = {
production: true,
testVar: process.env.TEST_VAR
};
Run Code Online (Sandbox Code Playgroud)
,所以我不必复制变量。
IE
我想从.env文件中解析变量,并在服务器上的打字稿编译期间将它们的值分配给角度环境变量。
如何才能做到这一点?也许用webpack?
更新
一些澄清。我的 .env 文件不包含 json。它看起来像这样:
TEST_VAR=1
Run Code Online (Sandbox Code Playgroud)
更新
由于ng eject 不适用于 Angular 6,我似乎无法侵入 webpack 配置。这里好像死路一条。
弹出
概述
暂时禁用。
弹出您的应用程序并输出正确的 webpack 配置和脚本。
bootstrap4 https://getbootstrap.com/docs/4.0/components/collapse/#accordion-example提供了手风琴控制
当我尝试将它与我的 angular 6 应用程序一起使用时,它不会崩溃。浏览器中没有错误,但它不起作用。对这个有什么想法吗?
html
<div class="accordion" id="accordionExample">
<div class="card">
<div class="card-header" id="headingOne">
<h5 class="mb-0">
<button class="btn btn-link" type="button" data-toggle="collapse" data-target="#collapseOne" aria-expanded="true" aria-controls="collapseOne">
Collapsible Group Item #1
</button>
</h5>
</div>
<div id="collapseOne" class="collapse show" aria-labelledby="headingOne" data-parent="#accordionExample">
<div class="card-body">
Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird …Run Code Online (Sandbox Code Playgroud) 我有一个带有输入字段的Angular 6组件。如果任何输入字段在用户试图离开时验证失败,则会触发该canDeactivate功能的守卫。守卫是通用的,因为这一逻辑需要发生在应用程序中的多个组件上。它运行起来很漂亮,但是当我尝试对这种行为进行单元测试时,canDeactivate从未达到过守卫中的功能。达到了守卫本身,但从未达到过功能。我是否以不正确的方式提供警卫?
防护组件接口
export interface GuardComponent {
canDeactivate: () => Observable<boolean> | Promise<boolean> | boolean;
}
Run Code Online (Sandbox Code Playgroud)
CanDeactivateGuard
export class CanDeactivateGuard implements CanDeactivate<GuardComponent> {
constructor() { }
canDeactivate(component: GuardComponent): Observable<boolean> | Promise<boolean> | boolean {
return component.canDeactivate();
}
}
Run Code Online (Sandbox Code Playgroud)
成分
export class MyComponent implements OnInit, GuardComponent {
...
canDeactivate() {
if (!this.form.invalid) {
return true;
}
this.isError = true;
return false;
}
}
Run Code Online (Sandbox Code Playgroud)
规格
const routes = [
{
path: 'my-component',
component: MyComponent,
canDeactivate: [CanDeactivateGuard], …Run Code Online (Sandbox Code Playgroud) javascript unit-testing jasmine angular-router-guards angular6
我创建了一个网站,使用 Angular 6 作为前端,使用 .Net Core 2.0 作为后端。我没有启用 SSR,到目前为止一切正常。现在,我正在尝试按照 Angular Universal 文档(https://angular.io/guide/universal)和 .Net Core 文档(https://docs.microsoft.com/en-us/aspnet/core)启用 SSR /client-side/spa/angular?view=aspnetcore-2.1&tabs=visual-studio&utm_source=jeliknes&utm_medium=blog&utm_campaign=medium&WT.mc_id=medium-blog-jeliknes#server-side-rendering)但失败了!
我认为问题出在 main.server.ts 文件上 - 根据 .NET Core 文档,我的 main.server.ts 应该如下所示:
import 'zone.js/dist/zone-node';
import 'reflect-metadata';
import { renderModule, renderModuleFactory } from '@angular/platform-server';
import { APP_BASE_HREF } from '@angular/common';
import { enableProdMode } from '@angular/core';
import { provideModuleMap } from '@nguniversal/module-map-ngfactory-loader';
import { createServerRenderer } from 'aspnet-prerendering';
export { AppServerModule } from './app/app.server.module';
enableProdMode();
export default createServerRenderer(params => {
const …Run Code Online (Sandbox Code Playgroud) 我想使用复选框按变量“类别”过滤 JSON 对象(产品)列表。
产品紧随其后:
{
'bikeId': 6,
'bikeName': 'Kids blue bike',
'bikeCode': 'KB-3075',
'releaseDate': 'June 28, 2016',
'description': 'Kids blue bike with stabalizers',
'category': 'kids',
'price': 290.00,
'starRating': 4.8,
'imageUrl': 'https://openclipart.org/image/2400px/svg_to_png/1772/bike-kid.png'
}
Run Code Online (Sandbox Code Playgroud)
我目前的 ngFor 循环如下:
<tr *ngFor="let product of products">
<td><img *ngIf='showImage'
[src]='product.imageUrl'
[title]='product.bikeName'
[style.width.px]='imageWidth'></td>
<td>{{product.bikeName}}</td>
<td>{{product.bikeCode}}</td>
<td>{{product.releaseDate}}</td>
<td>{{product.price}}</td>
<td>{{product.starRating}}</td>
</tr>
Run Code Online (Sandbox Code Playgroud)
我当前的复选框如下:
<input type="checkbox" name="All" value="true" /> Mens
<input type="checkbox" name="All" value="true" /> Womens
<input type="checkbox" name="All" value="true" /> Kids
Run Code Online (Sandbox Code Playgroud)
我问这个问题是因为我整天都在搜索论坛无济于事。有些答案确实回答了它,但是当我测试代码时,它要么已经过时,要么就是无法正常工作。任何帮助,将不胜感激。
我们可以将一个类(不是服务)作为共享实用程序,它可以通过角度依赖注入注入到服务甚至组件中吗?
我的实用类
export class MyUtilClass{
do(){
// something
}
}
Run Code Online (Sandbox Code Playgroud)
我的服务
export class MyService{
constructor(private uitl:MyUtilClass){
util.do();
}
}
Run Code Online (Sandbox Code Playgroud) 我有一个要完成的操作列表,如果设置了布尔值 promptRequired,我会显示一个对话框并根据它的值执行一些操作。
这里的问题是 for 循环并行运行并且所有操作同时执行,但我希望 for 循环同步运行并且循环必须等到对话框关闭。有解决办法吗?
async runActions() {
for (const action of Actions) {
if(action.promptRequired) {
const dialogRef = this.promptDialog.open(PromptDialogComponent, {
data: {action: action,
},
});
// await dialogRef.afterClosed();
}
}
const status = await this.httpService.getRequest('runAction', action)
// Do Some Action based on status
}
}
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试在 ng build 的资产副本期间重命名文件
这是我在angular.json:
"outputPath": "dist",
"assets": [
...,
{
"glob": "favicon-v1.png",
"input": "src/client",
"output": "/favicon.png"
},
...,
],
Run Code Online (Sandbox Code Playgroud)
不是创建文件dist/favicon.png,ng build而是创建一个dist/favicon.png/favicon-v1.png.
它似乎拒绝重命名文件 - 它总是使用我想使用的名称创建一个文件夹,favicon.png然后将原始文件放入其中。
这是预期的行为吗?任何不是文件重命名解决办法等favicon-v1.png,以favicong.png在源头控制?
我在用:
"@angular/cli": "^6.1.5"
"@angular/animations": "^6.0.1",
"@angular/common": "^6.0.1",
"@angular/compiler": "^6.0.1",
"@angular/core": "^6.0.1",
"@angular/forms": "^6.0.1",
"@angular/http": "^6.0.1",
"@angular/platform-browser": "^6.0.1",
"@angular/platform-browser-dynamic": "^6.0.1",
"@angular/router": "^6.0.1",
"@angular/upgrade": "^6.0.1",
Run Code Online (Sandbox Code Playgroud)
更新:类似的代码在 Angular 5 中与 angular-cli.json 一起工作正常。
angular6 ×10
angular ×8
javascript ×2
typescript ×2
.net-core ×1
async-await ×1
asynchronous ×1
bootstrap-4 ×1
checkbox ×1
collapse ×1
jasmine ×1
ng-bootstrap ×1
ng-packagr ×1
unit-testing ×1