我正在使用 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)
我问这个问题是因为我整天都在搜索论坛无济于事。有些答案确实回答了它,但是当我测试代码时,它要么已经过时,要么就是无法正常工作。任何帮助,将不胜感激。
我想使用nodejs buildpack将我的angular 6应用程序部署为PCF上的独立应用程序。有没有办法在不增加角度通用功能的情况下做到这一点。
如果不可能,如果我使用静态buildpack部署应用程序,是否可以读取PCF用户提供的环境变量?
我想自动聚焦在p对话框组件中的某个输入字段,该字段由绑定到对话框的visible属性的标志打开/关闭。
当我在输入标签中添加“自动对焦”属性时-仅在第一次打开对话框时才对其进行对焦。
当我使用“ onShow”事件时-在打开对话框之前将其发出。
当我添加“ autofocus”指令并尝试在AfterViewInit中设置焦点时-它仅被调用一次。
任何人都知道如何为对话框设置焦点或获取“ onAfterShow”事件吗?
我想使用此Angular 6代码实现文件下载:
REST API:
private static final Logger LOG = LoggerFactory.getLogger(DownloadsController.class);
private static final String EXTERNAL_FILE_PATH = "/Users/test/Documents/blacklist_api.pdf";
@GetMapping("export")
public ResponseEntity<FileInputStream> export() throws IOException {
File pdfFile = Paths.get(EXTERNAL_FILE_PATH).toFile();
HttpHeaders headers = new HttpHeaders();
headers.add("Cache-Control", "no-cache, no-store, must-revalidate");
headers.add("Pragma", "no-cache");
headers.add("Expires", "0");
return ResponseEntity.ok().headers(headers).contentLength(pdfFile.length())
.contentType(MediaType.parseMediaType("application/pdf"))
.body(new FileInputStream(pdfFile));
}
Run Code Online (Sandbox Code Playgroud)
服务:
import {Injectable} from '@angular/core';
import {HttpClient, HttpParams} from "@angular/common/http";
import {Observable} from "rxjs/index";
import {environment} from "../../../environments/environment";
import {HttpUtils} from "../common/http-utils";
import { map } from 'rxjs/operators';
import {Http, ResponseContentType} from …Run Code Online (Sandbox Code Playgroud) angular6 ×10
angular ×8
javascript ×2
.net-core ×1
bootstrap-4 ×1
checkbox ×1
collapse ×1
jasmine ×1
ng-bootstrap ×1
primeng ×1
spring ×1
spring-boot ×1
typescript ×1
unit-testing ×1