在使用Angular2的语义UI中,如果想要在组件中通过jQuery设置边栏,可以按照以下步骤进行操作:
<head>
标签中添加以下代码来引入:<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/semantic-ui/dist/semantic.min.css">
<script src="https://cdn.jsdelivr.net/npm/semantic-ui/dist/semantic.min.js"></script>ViewChild
装饰器来获取对边栏元素的引用。例如:import { Component, ViewChild, ElementRef } from '@angular/core';
@Component({
selector: 'app-sidebar',
templateUrl: './sidebar.component.html',
styleUrls: ['./sidebar.component.css']
})
export class SidebarComponent {
@ViewChild('sidebar', { static: true }) sidebar: ElementRef;
// 在这里可以使用jQuery来设置边栏的属性、样式等
ngAfterViewInit() {
// 示例:设置边栏的宽度为200px
$(this.sidebar.nativeElement).css('width', '200px');
}
}在上述代码中,@ViewChild('sidebar', { static: true })
表示通过选择器#sidebar
来获取对应的元素引用,sidebar: ElementRef
表示获取到的引用类型为ElementRef
。
SidebarComponent
。例如:<app-sidebar></app-sidebar>领取专属 10元无门槛券
手把手带您无忧上云