小编Aru*_*agi的帖子

如何在ts而不是HTML中使用管道

我从ts添加文本到html元素

像这样

this.legend.append('text')
  .attr('x', legendRectSize + legendSpacing)
  .attr('y', legendRectSize - legendSpacing)
  .text(function(d) { return d; });
Run Code Online (Sandbox Code Playgroud)

这将创建html之类的

<text>Data will come here</text>
Run Code Online (Sandbox Code Playgroud)

我想使用管道将这些数据转换成某种形式我该如何从ts代码中做到这一点?

当我动态创建这个HTML时,我不能像这样使用管道

<text>{{Data will come here | pipename}} </text>
Run Code Online (Sandbox Code Playgroud)

我正在寻找喜欢的东西

this.legend.append('text')
  .attr('x', legendRectSize + legendSpacing)
  .attr('y', legendRectSize - legendSpacing)
  .text(function(d) { return d; }).applypipe('pipename');
Run Code Online (Sandbox Code Playgroud)

javascript pipe angular

15
推荐指数
4
解决办法
2万
查看次数

打字稿中的静态类

有没有办法在typescript,node.js中创建一个静态类

我想创建一个静态类来保留所有常量和字符串.

什么是最好的方法呢?

javascript static node.js typescript

11
推荐指数
2
解决办法
1万
查看次数

根据mongoose,mongoDB中的条件填充

这是我的代码,以获得一个平面图并填充与此链接的所有单位

看下面的代码:

var floorplan = Floorplan.find({ 
    project: req.params.project, 
    tower: req.params.tower, 
    isDeleted: false 
});
floorplan.populate('flats').exec(function(err, floorplan) {
    if (err) { return res.send(err); }
    if (!floorplan) { return res.status(401).json(); }
    res.status(200).json(floorplan);
});
Run Code Online (Sandbox Code Playgroud)

但是我想只填充那些isDeleted的单位:false如何实现这个?

平面图的架构

var FloorplanSchema = new Schema({
    project: { type: Schema.ObjectId, ref: "Project" },
    flats: [{ type: Schema.ObjectId, ref: "Flat" }],
    tower: [{ type: Schema.ObjectId, ref: "Tower" }],
    unitType: String,
    area: Number,
    floorPlan2D: String,
    floorPlan3D: String,
    livingRoomArea: Number,
    kitchenArea: Number,
    balconies: Number,
    bathRooms: Number,
    isDeleted: { type: Boolean, 'default': false …
Run Code Online (Sandbox Code Playgroud)

mongoose mongodb node.js

10
推荐指数
1
解决办法
9086
查看次数

如何使用鼠标输入和鼠标退出或悬停

我想在鼠标悬停时显示和隐藏一个弹出/工具提示.

弹出窗口是多个,如下所示

 <div class="hotspot_info pointer" style="    top: {{towerPoint.posY}}%;    left: {{towerPoint.posX}}%;" *ngFor="#towerPoint of visualisation.towerPoints">
            <div class="tower-details"  style="    position: absolute;    top: -90px;    left: -84%;">
                <div class="popover top" style="display: block;">
                    <div class="arrow" style="left: 50%;"></div>
                    <h3 class="popover-title">{{towerPoint.tower.name}}</h3>
                    <div class="popover-content">Tower Name</div>
                </div>
            </div>
Run Code Online (Sandbox Code Playgroud)

在悬停到".tower-details"时,我想显示".popover",并在hideex".popover"的mouseexit上显示

javascript angular

8
推荐指数
1
解决办法
2万
查看次数

如何在角度 2 中处理 302

我收到状态 302 的错误但是在尝试在 catch 中记录错误时我收到了 200

post(url, data, successCallBack, errCallback) {
        return this.http.post(apiDomain + url, JSON.stringify(data), {
            headers: this.headers
        }).catch(this.handleError).subscribe(
            (res) => {
                successCallBack(res.json());
            },
            (err) => {
                errCallback(err);
            }
            );
    }

private handleError(error: any) {
    let errMsg = (error.message) ? error.message :
        error.status;
    console.log(error.status); // log is 200
    console.log(error)
    console.error(errMsg);
    return Observable.throw(errMsg);
}
Run Code Online (Sandbox Code Playgroud)

要求我想发送另一个关于重定向 URL 重定向的帖子调用。如何获取重定向 URL。

需要帮忙。

javascript ajax http angular

7
推荐指数
1
解决办法
1万
查看次数

在浏览器上保留应用的过滤器并转发Angular 2

我有产品列表页面,我有所有数据显示用户,如果用户正在应用过滤器,我使用Angular 2在客户端本身过滤列表,

现在,如果用户前进到项目详细信息页面并单击浏览器后退按钮,则所有应用的过滤器都应该消失,但我需要实现,以便在后退按钮上应该保留所有应用的过滤器.

解决方案我在想: -

方法:每当用户应用过滤器时,我们在URL中添加并重定向.

问题:在每个URL重定向API都将被调用.

有没有更好的方法可以解决这个问题?

javascript node.js single-page-application angular

6
推荐指数
1
解决办法
3190
查看次数

Gulp任务在无限循环中运行

我有一个gulp任务,将所有html文件从源复制到目标.

html gulp任务

var gulp = require('gulp');
module.exports = function() {
    return gulp.src('./client2/angularts/**/*.html')
    .pipe(gulp.dest('./client2/script/src/'));
 };
Run Code Online (Sandbox Code Playgroud)

并且每当我改变时开始运行的gulp手表.Html文件它swill start html gulp任务.

watch.ts

var gulp = require('gulp');
var watch = require('gulp-watch');
var  sq   = require('run-sequence');
module.exports = function () {

    var tsClientHtml = [
        'client2/**/*.html'
    ];



    watch(tsClientHtml, function () {
        gulp.run('html');
    });

};
Run Code Online (Sandbox Code Playgroud)

它进入无限循环,意味着每当我在html文件中更改它一次又一次破坏html gulp任务时...有人可以建议这个watch.ts有什么问题.

javascript node.js typescript gulp gulp-watch

1
推荐指数
1
解决办法
640
查看次数

根据javaScript中的给定顺序排序

我有像这样的对象数组:

var array = [
    { id: 1, color: red,    value: 1 },
    { id: 2, color: red,    value: 2 },
    { id: 3, color: yellow, value: 3 },
    { id: 4, color: yellow, value: 4 },
    { id: 5, color: green,  value: 4 }
];
Run Code Online (Sandbox Code Playgroud)

我想要排序顺序绿色 - >黄色 - >红色

array.sort(custmeSort()) 输出后应该是

[
    { id: 5, color: green,  value: 4 },   
    { id: 3, color: yellow, value: 3 },
    { id: 4, color: yellow, value: 4 },
    { id: …
Run Code Online (Sandbox Code Playgroud)

javascript sorting

0
推荐指数
1
解决办法
46
查看次数

排序和反向方法在JavaScript中无法正常工作

我这样想: -

[231, 907, 1246, 1203, 1305, 484, 709, 1220, 616, 1200].sort();
Run Code Online (Sandbox Code Playgroud)

输出是这样的: -

[1200, 1203, 1220, 1246, 1305, 231, 484, 616, 709, 907]
Run Code Online (Sandbox Code Playgroud)

其中我检查的第一个元素的数组typeof是数字.

任何想法为什么它不工作?

javascript

-1
推荐指数
1
解决办法
171
查看次数