【发布时间】:2016-12-09 05:27:05
【问题描述】:
当我的角度组件生成完成后,我需要使用 jquery 函数。我找到了下面的用法,但我无法让它工作。
import { Component, ViewChild, ElementRef, AfterViewInit } from '@angular/core';
import { Http } from '@angular/http';
declare var $:any;
@Component({
selector: 'nav-menu',
template: require('./NavMenu.component.html')
})
export class NavMenuComponent implements AfterViewInit {
@ViewChild('selectElem') el: ElementRef;
public navigation: IMenuItem[];
constructor(http: Http) {
http.get('http://localhost:52908/api/PageManager/Get?applicationID=3')
.subscribe(res => this.navigation = res.json().TransactionResult);
}
ngAfterViewInit(): any {
$(this.el.nativeElement).find('nav ul').jarvismenu({
accordion: true,
speed: true,
closedSign: '<em class="fa fa-plus-square-o"></em>',
openedSign: '<em class="fa fa-minus-square-o"></em>'
});
}
}
export interface IMenuItem {
PageID: number;
Code: string;
ApplicationID?: number;
DisplayText: string;
IconPath: string;
ParentID?: number;
IsFolder: boolean;
IsDefault: boolean;
ParentPage?: IMenuItem;
ChildPages: IMenuItem[];
BreadCrumb: string;
}
当我运行此代码时,我收到一个未定义 $ 的错误。我用一个数字变量尝试了它,它给出了同样的错误。看来我不能在课外声明任何东西。
顺便说一句,我也在使用 webpack。
谢谢。
【问题讨论】:
-
你在代码中使用 jquery 吗?
-
是的,我正在 html 中加载 jquery。它的工作原理我已经测试过了。
-
通过打字稿还是通过html?
-
你是在角度使用它吗?
-
Voa html。除了这里,没有在打字稿中使用任何 jquery。
标签: jquery asp.net-mvc angular asp.net-core webpack