小编Stw*_*sch的帖子

angular2 检测 ng-content 的变化

有没有办法检测 ng-content 的变化?

@Component({
    selector: 'example',
    template: `<ng-content></ng-content>`
})
export class Example {}

@Component({
    selector: 'test',
    template: `
        <example>
            <div *ngFor="let el of elements">{{el}}</div>
        </example>`
})
export class Test {
    elements = [1, 2, 3];

    ngOnInit() {
        setInterval(() => this.elements[0] += 10, 3000);
    }
}
Run Code Online (Sandbox Code Playgroud)

当我的 ng-content 发生变化时,我想在 Example 类中获取一些信息。

这里是plunker

javascript angular

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

单击按钮重复动画

我想每次单击按钮时都重复动画。我尝试做这样的事情。

const dist = document.querySelector('.dist');

document.querySelector('button').addEventListener('click', () => {
  dist.classList.remove('animation');
  dist.classList.add('animation');
});
Run Code Online (Sandbox Code Playgroud)
.dist {
  width: 100px;
  height: 100px;
  background: black;
  margin-bottom: 30px;
}

.animation {
  transform: scale(1.5);
  transition: transform 3s;
}
Run Code Online (Sandbox Code Playgroud)
<div class="dist"></div>
<button type="button">Trigger Animation</button>
Run Code Online (Sandbox Code Playgroud)

但实际上,这段代码只执行了一次。

dist.classList.remove('animation');
dist.classList.add('animation');
Run Code Online (Sandbox Code Playgroud)

这部分不应该删除状态并从头开始动画吗?

javascript css animation css-animations

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

不能在 TypeScript 的 Function 类型中使用“new”

我有这个代码:

const BlockConstructors: Function[] = [
 OBlock,
 IBlock,
 TBlock
];

function randomFromArray(array: any[]) {
  return array[Math.floor( Math.random() * array.length )];
}

const BlockConstructor: Function = random(BlockConstructors);
const block: Block = new BlockConstructor();
Run Code Online (Sandbox Code Playgroud)

我尝试从数组中绘制一些块构造函数,然后创建一个新对象,数组中的所有块构造函数都扩展了 Block 类。我得到错误:

不能将“new”用于类型缺少调用或构造签名的表达式。

为什么会出现这个错误?

typescript

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

我无法在Javascript中使用我的功能

我的函数change_slide()收到错误. ReferenceError: change_slide is not defined在第24:1行.我的代码在这里:

$(document).ready(function() {

    function change_slide() {
        number = pclass.charAt(6);
        number = parseInt(number);

        if (number == 5) number = 1;
        else number++;

        $('.picks').removeClass(pclass);
        pclass = 'bgpick' + number;
        $('.picks').addClass(pclass);
    }

    var random = Math.floor((Math.random() * 5) + 1);
    var pclass = 'bgpick' + random;
    var number;
    $('.picks').addClass(pclass);
    setInterval('change_slide()', 3000);
    $('.next').on('click', function() {
        change_slide();
    });
});
Run Code Online (Sandbox Code Playgroud)

单击.next上的change_slide()工作,在setInterval中不起作用.

javascript jquery

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