有没有一种简单的方法可以在Chrome JavaScript控制台中为不使用它的网站添加jQuery?例如,在网站上我想获取表格中的行数.我知道jQuery非常简单.
$('element').length;
Run Code Online (Sandbox Code Playgroud)
该网站不使用jQuery.我可以从命令行添加吗?
在Angular 1中,所有DOM操作都应该在指令中完成,以确保适当的可测试性,但是Angular 2呢?这怎么改变了?
我一直在寻找好的文章或任何关于DOM操作的位置以及在做这些操作时如何思考的信息,但我每次都是空的.
以这个组件为例(这实际上是一个指令,但让我们假装它不是):
export class MyComponent {
constructor(private _elementRef: ElementRef) {
this.setHeight();
window.addEventListener('resize', (e) => {
this.setHeight();
});
}
setHeight() {
this._elementRef.nativeElement.style.height = this.getHeight() + 'px';
}
getHeight() {
return window.innerHeight;
}
}
Run Code Online (Sandbox Code Playgroud)
例如,事件绑定是否属于构造函数,还是应该放在ngAfterViewInit函数中还是其他地方?您是否应该尝试将组件的DOM操作分解为指令?
这一切都只是一个模糊,所以我不确定我是否正确,我相信我不是唯一的.
Angular2中DOM操作的规则是什么?
我试图将Twitter时间线嵌入我的Angular 2应用程序.我按照本教程https://publish.twitter.com 然后我有了这个
<a class="twitter-timeline" href="https://twitter.com/TwitterDev">Tweets by TwitterDev</a> <script async src="//platform.twitter.com/widgets.js" charset="utf-8"></script>
Run Code Online (Sandbox Code Playgroud)
我将标记放入模板并将脚本标记放入index.html.这是一个例子.
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Angular 2 App | ng2-webpack</title>
<link rel="icon" type="image/x-icon" href="/img/favicon.ico">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.6.3/css/font-awesome.min.css">
<script async src="//platform.twitter.com/widgets.js" charset="utf-8"></script>
<base href="/">
</head>
<body>
<my-app>
<div class="loading-container">
<div class="loading"></div>
<div id="loading-text">loading</div>
<a class="twitter-timeline" href="https://twitter.com/TwitterDev">Tweets by TwitterDev</a>
</div>
</my-app>
</body>
</html>Run Code Online (Sandbox Code Playgroud)
但它只显示了一个标签,没有时间表.请帮我 !
我从服务器内容到json对象字段,它是html <style></style>和<script></script>标签,我想这样执行它:
[innerHtml] ="content | sanitize",但<script></script>标签不执行.它可以使它工作吗?
我的消毒管看起来像这样:
import {Pipe} from '@angular/core';
import {DomSanitizationService} from '@angular/platform-browser';
@Pipe({
name: 'sanitize',
pure: true
})
export class Sanitize {
constructor(private sanitizer: DomSanitizationService) {
}
transform(html: string) {
return this.sanitizer.bypassSecurityTrustHtml(html);
}
}
Run Code Online (Sandbox Code Playgroud)
我知道,DomSanitizationService中有bypassSecurityTrustScript函数,但我怎么能在我的情况下使用它呢?