目录搜索
AngularJS API Referenceautoauto/serviceauto/service/$injectorauto/service/$providengng/directiveng/directive/ang/directive/formng/directive/inputng/directive/input[checkbox]ng/directive/input[date]ng/directive/input[dateTimeLocal]ng/directive/input[email]ng/directive/input[month]ng/directive/input[number]ng/directive/input[radio]ng/directive/input[text]ng/directive/input[time]ng/directive/input[url]ng/directive/input[week]ng/directive/ngAppng/directive/ngBindng/directive/ngBindHtmlng/directive/ngBindTemplateng/directive/ngBlurng/directive/ngChangeng/directive/ngCheckedng/directive/ngClassng/directive/ngClassEvenng/directive/ngClassOddng/directive/ngClickng/directive/ngCloakng/directive/ngControllerng/directive/ngCopyng/directive/ngCspng/directive/ngCutng/directive/ngDblclickng/directive/ngDisabledng/directive/ngFocusng/directive/ngFormng/directive/ngHideng/directive/ngHrefng/directive/ngIfng/directive/ngIncludeng/directive/ngInitng/directive/ngKeydownng/directive/ngKeypressng/directive/ngKeyupng/directive/ngListng/directive/ngModelng/directive/ngModelOptionsng/directive/ngMousedownng/directive/ngMouseenterng/directive/ngMouseleaveng/directive/ngMousemoveng/directive/ngMouseoverng/directive/ngMouseupng/directive/ngNonBindableng/directive/ngOpenng/directive/ngPasteng/directive/ngPluralizeng/directive/ngReadonlyng/directive/ngRepeatng/directive/ngSelectedng/directive/ngShowng/directive/ngSrcng/directive/ngSrcsetng/directive/ngStyleng/directive/ngSubmitng/directive/ngSwitchng/directive/ngTranscludeng/directive/ngValueng/directive/scriptng/directive/selectng/directive/textareang/filterng/filter/currencyng/filter/dateng/filter/filterng/filter/jsonng/filter/limitTong/filter/lowercaseng/filter/numberng/filter/orderByng/filter/uppercaseng/functionng/function/angular.bindng/function/angular.bootstrapng/function/angular.copyng/function/angular.elementng/function/angular.equalsng/function/angular.extendng/function/angular.forEachng/function/angular.fromJsonng/function/angular.identityng/function/angular.injectorng/function/angular.isArrayng/function/angular.isDateng/function/angular.isDefinedng/function/angular.isElementng/function/angular.isFunctionng/function/angular.isNumberng/function/angular.isObjectng/function/angular.isStringng/function/angular.isUndefinedng/function/angular.lowercaseng/function/angular.moduleng/function/angular.noopng/function/angular.toJsonng/function/angular.uppercaseng/objectng/object/angular.versionng/providerng/provider/$animateProviderng/provider/$compileProviderng/provider/$controllerProviderng/provider/$filterProviderng/provider/$httpProviderng/provider/$interpolateProviderng/provider/$locationProviderng/provider/$logProviderng/provider/$parseProviderng/provider/$rootScopeProviderng/provider/$sceDelegateProviderng/provider/$sceProviderng/serviceng/service/$anchorScrollng/service/$animateng/service/$cacheFactoryng/service/$compileng/service/$controllerng/service/$documentng/service/$exceptionHandlerng/service/$filterng/service/$httpng/service/$httpBackendng/service/$interpolateng/service/$intervalng/service/$localeng/service/$locationng/service/$logng/service/$parseng/service/$qng/service/$rootElementng/service/$rootScopeng/service/$sceng/service/$sceDelegateng/service/$templateCacheng/service/$timeoutng/service/$windowng/typeng/type/$cacheFactory.Cacheng/type/$compile.directive.Attributesng/type/$rootScope.Scopeng/type/angular.Moduleng/type/form.FormControllerng/type/ngModel.NgModelControllerngAnimatengAnimate/providerngAnimate/provider/$animateProviderngAnimate/servicengAnimate/service/$animatengCookiesngCookies/servicengCookies/service/$cookiesngCookies/service/$cookieStorengMessagesngMessages/directivengMessages/directive/ngMessagengMessages/directive/ngMessagesngMockngMock/functionngMock/function/angular.mock.dumpngMock/function/angular.mock.injectngMock/function/angular.mock.modulengMock/objectngMock/object/angular.mockngMock/providerngMock/provider/$exceptionHandlerProviderngMock/servicengMock/service/$exceptionHandlerngMock/service/$httpBackendngMock/service/$intervalngMock/service/$logngMock/service/$timeoutngMock/typengMock/type/angular.mock.TzDatengMockE2EngMockE2E/servicengMockE2E/service/$httpBackendngResourcengResource/servicengResource/service/$resourcengRoutengRoute/directivengRoute/directive/ngViewngRoute/providerngRoute/provider/$routeProviderngRoute/servicengRoute/service/$routengRoute/service/$routeParamsngSanitizengSanitize/filterngSanitize/filter/linkyngSanitize/servicengSanitize/service/$sanitizengTouchngTouch/directivengTouch/directive/ngClickngTouch/directive/ngSwipeLeftngTouch/directive/ngSwipeRightngTouch/servicengTouch/service/$swipe
文字

AngularJS: API: ng/function/angular.element

angular.element

  1. - function in module ng

封装一个原始DOM元素或HTML字符串为一个 jQuery 元素。

如果存在jQuery, angular.element 作为jQuery 函数的别名。如果不存在jQuery,angular.element委托到Angular内建的jQuery子集,称为"jQuery lite" 或 "jqLite."

jqLite是一个微型的、API兼容的jQuery子集,允许Angular在跨浏览器兼容的方式下操纵DOM。jqLite只实现了所需的最常用功能。

要使用jQuery,只要简单的在DOMContentLoaded事件触发前载入即可。

注意: Angular中所有元素引用都用jQuery或jqLite进行了封装,从不会直接引用原始DOM。

Angular的jqLite

jqLite只提供了以下jQuery方法:

  • addClass()
  • after()
  • append()
  • attr()
  • bind() - 不支持namespaces、selectors或eventData
  • children() - 不支持selectors
  • clone()
  • contents()
  • css()
  • data()
  • empty()
  • eq()
  • find() - 只限于根据标签名查找
  • hasClass()
  • html()
  • next() - 不支持selectors
  • on() - 不支持namespaces、selectors或eventData
  • off() - 不支持namespaces、selectors
  • one() - 不支持namespaces、selectors
  • parent() - 不支持selectors
  • prepend()
  • prop()
  • ready()
  • remove()
  • removeAttr()
  • removeClass()
  • removeData()
  • replaceWith()
  • text()
  • toggleClass()
  • triggerHandler() - 传递一个虚拟的事件对象到handlers
  • unbind() - 不支持namespaces
  • val()
  • wrap()

jQuery/jqLite 扩展

Angular同时提供了以下额外的方法和事件到jQuery和jqLite:

事件

  • $destroy - AngularJS拦截所有jqLite/jQuery的DOM销毁api,并在所有DOM 节点被移除时触发这个事件。这可以在它被移除前用于清除任何绑定到DOM元素的第三方内容。

方法

  • controller(name) -获取当前元素或它父亲的控制器。默认获取的控制器与ngController指令相关。如果name 是驼峰式的指令名,这个指令的控制器会被获取到(如: 'ngModel')。
  • injector() - 获取当前元素或它父亲的注入。
  • scope() - 获取当前元素或它父亲的 scope 。
  • isolateScope() - 获取直接附加到当前元素的独立 scope。这个获取器只能用于包含开始一个新的独立域的指令的元素上。在这个元素上调用scope()永远返回原始的非独立域。
  • inheritedData() - 等同于 data(), 但是会遍历DOM直到找到一个值或到达最顶部父元素。

用法

angular.element(element);

参数

参数 类型 详述
element stringDOMElement

要被封装到jQuery的HTML字符串或DOM元素。

返回值

Object

jQuery对象。


上一篇:下一篇: