How to use jqlite in angular.js
PHP中文网
PHP中文网 2017-05-15 16:50:05
0
6
635

Instructions in the documentation:

angular.element(element)

My own call:

angular.element("xx").addClass("xx")

It’s impossible to implement it at all. Can anyone explain it?

http://jsfiddle.net/twn39/sy38y/1/

PHP中文网
PHP中文网

认证0级讲师

reply all(6)
習慣沉默

Although angular.element is very close to jQuery, it is still not possible to obtain elements directly through HTML tags. The simplest way is as follows:

angular.element(document.querySelector('p'));

http://jsfiddle.net/sy38y/2/

我想大声告诉你

You can see it by looking at the document
The parameter requirement of angular.element() is HTML string or DOMElement, but what you write is a selector, which does not meet the parameter requirement of angular.element. If you want to use this usage, you need to add jquery

淡淡烟草味

Change it to this:

    var par = document.getElementsByTagName('p')[0];
    angular.element(par).addClass('blue');
迷茫

Angular does not recommend direct manipulation of the DOM, so if you want to add class, it is recommended to do so (I can't open your connection, I don't know how you wrote the code, so I will use my own)

HTML

<button ng-click="showActive()"></button>
<p ng-class="{'active':show===1}"></p>

js

$scope.showActive=function(){
    $scope.show=1;
}
伊谢尔伦
angular.element(document).find('xx').addClass('yy')
仅有的幸福

Yes, I originally thought about passing the currently clicked button object through ng-click, but in the end I found that Angular does not allow this. . .
I had no choice but to use angular’s ​​built-in jQlite to handle it!

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template