我只是将函数复制到此处(https://www.tradingview.com/widget/advanced-chart/)的嵌入脚本中,并将其复制到Angular 5应用程序的组件中,并将源脚本包含在angular-cli.json中。但是,该组件返回错误“找不到名称'TradingView'”。有人有什么建议吗?
我有一个由 ng2-smart-table 构建的表,表中的数据有两种状态Draft
和Ready
。当 时data.status = 'Draft'
,可以出于 CRUD 目的显示操作列,但随后状态更改为data.status = 'Ready'
,我想禁用操作列。如何有条件地做到这一点?
桌面设置:
tableSettings = {
add: {
addButtonContent: '<i class="fas fa-plus fa-fw"></i>',
createButtonContent: '<i class="fas fa-plus fa-fw"></i>',
cancelButtonContent: '<i class="fas fa-times fa-fw"></i>',
confirmCreate: true
},
edit: {
editButtonContent: '<i class="fas fa-pencil-alt fa-fw"></i>',
saveButtonContent: '<i class="fas fa-check fa-fw"></i>',
cancelButtonContent: '<i class="fas fa-times fa-fw"></i>',
confirmSave: true
},
delete: {
deleteButtonContent: '<i class="far fa-trash-alt fa-fw"></i>',
confirmDelete: true
},
columns: {
title: {
title: 'Title',
type: 'text', …
Run Code Online (Sandbox Code Playgroud) 我将 jsQR ( https://www.npmjs.com/package/jsqr ) 与我的 Angular 应用程序一起使用来解码 QR。一般来说,我将代码从 jsQR 复制到我的应用程序中,它立即可以运行。但是,jsQR 仅当我在网络摄像头区域中持有二维码时才读取,当将代码移开时,不会捕获之前的结果。所以我想如果成功的话捕获第一个二维码并将其绑定到表单中以提交结果。我怎样才能正确地做到这一点?
到目前为止,这是我的代码:
ngOnInit() {
this.getQR();
}
getQR() {
const video = document.createElement('video');
const canvasElement: any = document.getElementById('canvas');
const canvas = canvasElement.getContext('2d');
const outputContainer = document.getElementById('output');
const outputMessage = document.getElementById('outputMessage');
const outputData = document.getElementById('outputData');
function drawLine(begin, end, color) {
canvas.beginPath();
canvas.moveTo(begin.x, begin.y);
canvas.lineTo(end.x, end.y);
canvas.lineWidth = 4;
canvas.strokeStyle = color;
canvas.stroke();
}
// Use facingMode: environment to attemt to get the front camera on phones
navigator.mediaDevices.getUserMedia({ video: { facingMode: 'environment' …
Run Code Online (Sandbox Code Playgroud) 我在这里遵循日期过滤的文档:https :
//www.ag-grid.com/javascript-grid-filter-date/#gsc.tab=0
但是,当我尝试过滤日期时,它不起作用. 过滤后的结果与之前相同,而其他列如文本和数字则起作用。核心问题应该是在Date对象里面gridOptions
。我将 Angular 日期管道的日期显示格式化为与 ag-grid 的过滤格式相同的格式,但实际的日期数据是这样的:“2017-12-19T08:29:19Z”。不知道会不会影响过滤方式。
版本:Angular 4+、ag-grid 15.0.0、ag-grid-angular 15.0.0
这是我的代码:
import { Component, OnInit } from '@angular/core';
import { DatePipe } from '@angular/common';
import { GridOptions, GridApi } from "ag-grid";
import { ApiService } from '../../services/api.service/api.service';
import * as Models from '../../models/models';
@Component({
selector: 'app-orders',
templateUrl: './orders.component.html',
styleUrls: ['./orders.component.scss']
})
export class OrdersComponent implements OnInit {
gridOptions: GridOptions;
gridApi: GridApi;
gridColumnApi;
rowSelection;
orders: Models.Order[] = [];
constructor(
private apiService: ApiService,
private modalService: NgbModal, …
Run Code Online (Sandbox Code Playgroud) 我有一个数组:
var arr = [
{price: 5, amount: 100},
{price: 3, amount: 50},
{price: 10, amount: 20},
{price: 3, amount: 75},
{price: 7, amount: 15},
{price: 3, amount: 65},
{price: 2, amount: 34}
]
Run Code Online (Sandbox Code Playgroud)
我想删除具有相同价格的重复项,并且仅保留最后一个重复项,然后根据价格从最高到最低对数组进行排序.这是我想要的结果:
var result = [
{price: 10, amount: 20},
{price : 7, amount: 15},
{price: 5, amount: 100},
{price: 3, amount: 65},
{price: 2, amount: 34}
]
Run Code Online (Sandbox Code Playgroud) 我用来ngrx/store
实现登录操作,该操作从订阅商店获取日期。登录组件是一个模式,当我输入错误的密码时,我得到data.type === 'LOGIN_FAILED'
,但是,当我关闭模式并重新打开它时,数据操作仍然是LOGIN_FAILED
而不是INIT
。因此,登录操作不是取消订阅,我尝试手动取消订阅,但不起作用。如何正确取消订阅登录操作?
import { Component, OnInit, ViewChildren, OnDestroy } from '@angular/core';
// shared
import { ToasterService } from '../../shared/providers/toaster-service/toaster.service';
// ngx-bootstrap
import { BsModalRef } from 'ngx-bootstrap/modal/bs-modal-ref.service';
// ngrx
import { ActionsSubject } from '@ngrx/store';
// rxjs
import { Subscription } from 'rxjs/Subscription';
loading = <boolean>false;
actionSub = new Subscription();
errorMessage = <string>'';
constructor(
private actionsSubj: ActionsSubject,
private toastService: ToasterService,
private bsModalRef: BsModalRef,
) {
this.actionSub = this.actionsSubj.subscribe((data: any) => { …
Run Code Online (Sandbox Code Playgroud) 我尝试使用bitfinex库(https://www.npmjs.com/package/bitfinex)从Bitfinex调用rest API .当使用相同的API密钥同时运行多个进程时,文档警告此错误.但是,我相信我只是一次运行一个进程,即使我生成新的API密钥,错误仍然会发生.我正在考虑重写nonce或扩展它但我不知道如何做到这一点.我曾在互联网上尝试过一些建议,但仍然无效.
以下是我的参考代码:
import Bitfinex = require('bitfinex');
import pollingtoevent = require('polling-to-event');
import { Logger, LoggerFactory } from '../../common';
import { AppDataServices } from '../../data';
export class BitfinexPoller {
private static readonly LOGGER: Logger = LoggerFactory.getLogger();
private bitfinex: any = undefined;
private emitter: any = undefined;
private public_key: string = '<my-public-key>';
private secret_key: string = '<my-secret-key>';
private nonce: any = new Date().getTime();
constructor(private appServices: AppDataServices) {
BitfinexPoller.LOGGER.info('Bitfinex poller init');
this.bitfinex = new Bitfinex(this.public_key, this.secret_key, this.nonce);
// Lend book …
Run Code Online (Sandbox Code Playgroud) 如果我将Twitter文档(https://dev.twitter.com/web/javascript/loading)中的内置函数完全复制到ngAfterViewInit函数中,则我的应用程序将运行正常,但是当我切换路线时,小部件也会消失。
以下是仅适用于首页加载的代码:
import { Component, OnInit, OnDestroy, AfterViewInit } from '@angular/core';
import { Router, NavigationEnd, ActivatedRoute, ParamMap, Params } from '@angular/router';
import { Observable, Subscription } from 'rxjs/Rx';
export class ProjectDetailComponent implements OnInit, OnDestroy, AfterViewInit {
constructor(
private route: ActivatedRoute,
private router: Router
) { }
ngOnInit(){}
ngAfterViewInit(){
(<any>window).twttr = (function(d, s, id) {
let js, fjs = d.getElementsByTagName(s)[0],
t = (<any>window).twttr || {};
if (d.getElementById(id)) return t;
js = d.createElement(s);
js.id = id;
js.src = 'https://platform.twitter.com/widgets.js';
fjs.parentNode.insertBefore(js, …
Run Code Online (Sandbox Code Playgroud) 我使用 ng-bootstrap 创建 3 个选项卡,每个选项卡都是一个相互父组件内的单独组件。每个子组件包含多个文本输入,当我在子组件之间切换时,输入文本值消失了。切换标签页时如何保留所有输入值?
我可以使用 序列化JsonPatchDocument
模型JsonConvert.SerializeObject()
,但结果类型是字符串,如何将其转换为普通数组类型?或者如何将JsonPatchDocument
对象直接放入数组?
var pathSerialized = JsonConvert.SerializeObject(patch);
Console.WriteLine(pathSerialized);
// Result as string:
// "[{"value":"2018-08-30","path":"/openTo","op":"replace"},{"value":"2018-04-01","path":"/openFrom","op":"replace"}]"
Run Code Online (Sandbox Code Playgroud) 我想使用路由GET创建一个控制器,api/auth/user
以返回当前登录用户的详细信息。我创建的api api/auth/login
处理令牌在15分钟内过期。那么哪种方法可以返回当前登录用户的ID?
这是我当前的代码:
auth-controller.cs:
[Route("api/auth")]
public class AuthController : Controller
{
private readonly IAuthRepository repo;
private readonly IConfiguration config;
private readonly IUserRepository userRepo;
public AuthController(IAuthRepository repo, IConfiguration config, IUserRepository userRepo)
{
this.userRepo = userRepo;
this.config = config;
this.repo = repo;
}
[HttpPost("login")]
public async Task<IActionResult> Login([FromBody]UserForLogin userForLogin)
{
var userFromRepo = await this.repo.Login(userForLogin.Email.ToLower(), userForLogin.Password);
if (userFromRepo == null)
return Unauthorized();
// generate token
var tokenHandler = new JwtSecurityTokenHandler();
var key = Encoding.ASCII.GetBytes(this.config.GetSection("AppSettings:Token").Value);
var tokenDescriptor = new SecurityTokenDescriptor …
Run Code Online (Sandbox Code Playgroud) angular ×7
c# ×2
ag-grid ×1
asp.net ×1
asp.net-core ×1
ecmascript-6 ×1
javascript ×1
json-patch ×1
ngrx ×1
nonce ×1
qr-code ×1
rest ×1
rxjs ×1
twitter ×1
typescript ×1