我需要在每秒更新的用户界面上显示时差。
我尝试的是:
组件.ts
import { Component, OnInit } from '@angular/core';
import 'rxjs/add/observable/of';
import 'rxjs/add/observable/interval';
import 'rxjs/add/operator/map';
import { Observable, Subscription } from 'rxjs/Rx';
import { DateUtil } from '../../../framework/Utils/DateUtil';
@Component({
selector: 'app-time-difference',
templateUrl: './time-difference.component.html',
styleUrls: ['./time-difference.component.scss']
})
export class TimeDifferenceComponent implements OnInit {
orderTime = '14-09-2018 14:00:00';
today = new Date();
clock: Observable<any>;
timeDifference: string;
constructor() { }
ngOnInit() {
this.clock = Observable
.interval(1000)
.map(() => {
const orderDate = DateUtil.getDatefromString(this.orderTime, 'DD-MM-YYYY HH:mm:ss');
const timeDifference = DateUtil.getDateDiffInHours(orderDate, new Date());
return …Run Code Online (Sandbox Code Playgroud) 我有一个像这样的登录功能:
login() {
// clear error text
this.state.errorText = "";
// try to login
this.sb.login(this.model.username, this.model.password).subscribe(x => {
// check if ok
if (x.success) {
console.log('does this print') //<-- outputs as expected
this.router.navigate(['/app']);
} else {
this.state.errorText = x.response;
}
});
}
Run Code Online (Sandbox Code Playgroud)
通过调试器,我可以看到 x.success 返回 true。我的 console.log 打印但之后, this.router.navigate(...) 行似乎没有做任何事情。没有重定向。
我尝试过使用:
this.zone.run(() => this.router.navigate(['/app']));
Run Code Online (Sandbox Code Playgroud)
但这会导致相同的结果,没有页面重定向。
我有一个端点,它根据某些参数为我提供图像。这不是一个图像网址,而是一个普通图像。因此,当我到达邮递员中的端点时,作为响应,我收到一张图像(JPG)。
我是否可以在变量中接收该图像并将其绑定到 HTML 标签中?
所有问题都有将图像 url 映射到图像的解决方案,而我的是必须在 UI 中显示的图像。
显示图像组件.ts
this.appservice.getImage().subscribe((image) => {
console.log(image);
}
)
Run Code Online (Sandbox Code Playgroud)
服务.ts
getImg() {
return this.httpClient.get('xyz.com', {headers: this.httpHeaders});
}
Run Code Online (Sandbox Code Playgroud)
我应该如何在 HTML 上显示图像变量中收到的图像?
实际日志顺序:('ngOnInit开始') ('在我之后aaya', this.policydetails) ('这里', Object.keys(this.policy).length)
预期的日志顺序:('ngOnInit开始') ('这里', Object.keys(this.policy).length) ('在我之后aaya', this.policydetails)
Component.ts 文件片段如下:
ngOnInit() {
console.log('ngOnInit started');
this.route.params.subscribe(params => {
this.getPoliciesService.getPolicyDetails(params.policyNo)
.subscribe((data: PoliciesResponse) => {
this.policy = data.data[0];
this.flattenPolicy();
console.log('Here', Object.keys(this.policy).length);
});
});
this.makePolicyTable();
}
ngAfterViewInit() {
console.log('after me aaya', this.policydetails);
const table = this.policydetails.nativeElement;
table.innerHTML = '';
console.log(table);
console.log(this.table);
table.appendChild(this.table);
console.log(table);
}
Run Code Online (Sandbox Code Playgroud)
Service.ts 文件片段如下:
getPolicyDetails(policyNo) {
const serviceURL = 'http://localhost:7001/getPolicyDetails';
console.log('getPolicyDetails service called, policyNo:', policyNo);
const params = new HttpParams()
.set('policyNo', policyNo);
console.log(params);
return this.http.get<PoliciesResponse>(serviceURL, {params} );
}
Run Code Online (Sandbox Code Playgroud)
与以下 API …
我想知道使用 Angular Flex-Layout 模块是否真的是一个好习惯。难道它只是糖衣内联样式,会带来额外的性能成本,因为样式是由 JavaScript 完成的吗?所以,如果可以的话,请向我解释一下为什么我应该使用它而不是基本的弹性盒?
我无法将 DataTableModule 包含到带有数据表的 Angular 6 项目中。我正在使用带有数据表的 Angular cli 6。我的代码显示找不到模块 DataTablesModule 的错误。我已经安装了与 datatable 和 jquery 相关的所有软件包。它也显示到 node_modules 文件夹中,但无法添加到 app.module.ts 中。
我附上下面的屏幕截图:
这是我的代码。
在浏览器中出现此错误
因此,目前我正在路由到一个页面以从策略中获取文档列表。我还引入了所有保单,以便您可以浏览选择表单并通过传递的保单编号将您重新路由到该表单。有没有办法选择使用新网址进行导航的选项?
<mat-form-field name="selectPolicy">
<mat-select placeholder="Change Policy">
<mat-option *ngFor="let policy of policies"
[routerLink]="['../', policy.policyNbr]">{{policy.policyTypeDesc}}
#{{policy.policyNbr}}
</mat-option>
</mat-select>
</mat-form-field>
Run Code Online (Sandbox Code Playgroud)
截至目前,这会更改我的网址,但一旦更改就会提交到新页面。
我有以下路线。
http://localhost:4100/示例/5b8c94cfc5f85728db8bddf2/5bb426434722020c569fc5d8/(p1:.... // p2:.... // p3:...)
我有 3 条辅助路线,当我执行以下操作时遇到问题
this.router.navigate ([<any path>], {relativeTo: this.route})
Run Code Online (Sandbox Code Playgroud)
,我在主出口航行,但次要出口 p1、p2、p3 未保留
有没有等于preserveQueryParams的东西?,navigationExtras? https://angular.io/api/router/NavigationExtras 但对于辅助路线?
尝试创建用于学习目的的自定义指令。我无法确定为什么 Angular 6 中的 renderer2 不显示图像背景的问题。
我使用的是 cli,因此在 app.module.ts 中注册指令没有问题
@Directive({
selector: '[bgIMG]'
})
export class MyCustomStyleDirective {
// private url = "http://www.publicdomainpictures.net/pictures/50000/velka/flower-meadow.jpg"
constructor(elm : ElementRef, renderer2:Renderer2) {
renderer2.setStyle(elm.nativeElement, 'background-image', 'url ("http://www.publicdomainpictures.net/pictures/50000/velka/flower-meadow.jpg")')
}
}
Run Code Online (Sandbox Code Playgroud)
<div bgIMG></div>
Run Code Online (Sandbox Code Playgroud)
哪里错了.? 我也没有发现任何控制台错误。
import { Directive,ElementRef, Renderer2, HostListener } from '@angular/core';
@Directive({
selector: '[bgIMG]'
})
export class MyCustomStyleDirective {
constructor( renderer: Renderer2, el: ElementRef) {
renderer.setStyle(el.nativeElement, 'background-image','http://www.publicdomainpictures.net/pictures/50000/velka/flower-meadow.jpg');
renderer.setStyle(el.nativeElement, 'font-weight','bold');
}
}
html
-----
<div class="container">
<div class="row">
<div bgIMG>
<p>some text</p>
</div>
</div> …Run Code Online (Sandbox Code Playgroud) 我想使用以下 Angular 6 代码实现文件下载:
休息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<InputStreamResource> export() throws IOException {
ClassPathResource pdfFile = new ClassPathResource(EXTERNAL_FILE_PATH);
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.contentLength())
.contentType(MediaType.parseMediaType("application/pdf"))
.body(new InputStreamResource(pdfFile.getInputStream()));
}
Run Code Online (Sandbox Code Playgroud)
服务:
import {Component, OnInit} from '@angular/core';
import {DownloadService} from "../service/download.service";
import {ActivatedRoute, Router} from "@angular/router";
import {flatMap} from "rxjs/internal/operators";
import {of} from "rxjs/index";
import { map } from 'rxjs/operators';
@Component({ …Run Code Online (Sandbox Code Playgroud) angular ×10
angular6 ×10
rxjs ×2
angular5 ×1
angular7 ×1
datatable ×1
flexbox ×1
html ×1
java ×1
javascript ×1
momentjs ×1
node.js ×1
observable ×1
router ×1
spring ×1
spring-boot ×1
typescript ×1