How can I use methods of jqLite in AngularJS

Maksim

How to use methods's of qjLite in AngularJS? I want to add 'p' html element and following to add class="red" .

Maybe I something doing wrong...

Here code which I wrote:

angular.module('app', [])
 .controller('ctrl', function($scope){
 $scope.text = 'Test';
 });

 var span = angular.element('<span> </span>');

 span.append('<p>Run it</p>');
 span.addClass('red');
 .red{
 color: red;
 font-size: 60px;
 }
<!DOCTYPE html>
<html ng-app="app">
<head lang="en">
 <meta charset="UTF-8">
 <title></title>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.22/angular.min.js"></script>
</head>
<body ng-controller="ctrl">
<p ng-bind="text"></p>
<span></span>
</body>
</html>

Anand G

Create directive to work with DOM element and then use jqLite methods. The jQlite is similar to jQuery but to use them in Angular Create directive, wherein the element is accessible

Try below

var myApp = angular.module('myApp',[]);

 myApp.controller('ctrl', function($scope){
 $scope.text = 'Test';
   
 });
myApp.directive('addElement', function() {
    return {
        restrict: 'EA',
        replace: false,
        link: function(scope, element) {
             element.html('<p>Run it</p>');
 element.addClass('red');
        }
    }
});
.red{
 color: red;
 font-size: 60px;
 }
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.21/angular.min.js"></script>

<body ng-app="myApp" ng-controller="ctrl">
<p ng-bind="text"></p>
<span add-element></span>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

AngularJS : Stubbing JQlite methods

From Dev

Using AngularJS Jqlite, how can I find the first child of an element that is of a certain element type?

From Dev

Using AngularJS Jqlite, how can I find the first child of an element that is of a certain element type?

From Dev

How can I grab an element's attr data in angular with jqlite?

From Dev

How can i use ajax with angularJS?

From Dev

How can I use Bengali in an AngularJS script?

From Dev

How to add CSS property for firstchild with AngularJS (jqLite)

From Dev

Why can I use 'this' in methods

From Dev

How can I use same methods in different classes type ArrayList?

From Dev

How can I use jQuery promises when referring to methods of an object?

From Dev

How can I use jQuery methods on elements accessed by brackets notation?

From Dev

How can I use functools.singledispatch with instance methods?

From Dev

How can I use the new FormData methods apart from append?

From Dev

How can I use set methods to set data field?

From Dev

how can I use @Enclosed without making methods as static

From Dev

How can I use multiple HTTP methods in simple_form?

From Dev

How can I use descriptors for non-static methods?

From Dev

How can I use lambdas with methods in C#?

From Dev

How can I use composition with methods in ES6 Classes?

From Dev

How can I use global functions in Angularjs Protractor?

From Dev

How can I use command line arguments in Angularjs Protractor?

From Dev

How can I use System Environment Variables in Angularjs Protractor?

From Dev

How can I use angular-cache in conjunction with the AngularJS LocalStorageModule

From Dev

How can I do validation and use ..$setPristine(); in an AngularJS form?

From Dev

How can I change my AngularJS service to use Typescript?

From Dev

How can I use the AngularJS hash option of $q.all?

From Dev

How can I use image form json response using angularjs?

From Dev

AngularJS - How can I use .config() method with my own services?

From Dev

How can I use HTML5 geolocation in angularjs

Related Related

  1. 1

    AngularJS : Stubbing JQlite methods

  2. 2

    Using AngularJS Jqlite, how can I find the first child of an element that is of a certain element type?

  3. 3

    Using AngularJS Jqlite, how can I find the first child of an element that is of a certain element type?

  4. 4

    How can I grab an element's attr data in angular with jqlite?

  5. 5

    How can i use ajax with angularJS?

  6. 6

    How can I use Bengali in an AngularJS script?

  7. 7

    How to add CSS property for firstchild with AngularJS (jqLite)

  8. 8

    Why can I use 'this' in methods

  9. 9

    How can I use same methods in different classes type ArrayList?

  10. 10

    How can I use jQuery promises when referring to methods of an object?

  11. 11

    How can I use jQuery methods on elements accessed by brackets notation?

  12. 12

    How can I use functools.singledispatch with instance methods?

  13. 13

    How can I use the new FormData methods apart from append?

  14. 14

    How can I use set methods to set data field?

  15. 15

    how can I use @Enclosed without making methods as static

  16. 16

    How can I use multiple HTTP methods in simple_form?

  17. 17

    How can I use descriptors for non-static methods?

  18. 18

    How can I use lambdas with methods in C#?

  19. 19

    How can I use composition with methods in ES6 Classes?

  20. 20

    How can I use global functions in Angularjs Protractor?

  21. 21

    How can I use command line arguments in Angularjs Protractor?

  22. 22

    How can I use System Environment Variables in Angularjs Protractor?

  23. 23

    How can I use angular-cache in conjunction with the AngularJS LocalStorageModule

  24. 24

    How can I do validation and use ..$setPristine(); in an AngularJS form?

  25. 25

    How can I change my AngularJS service to use Typescript?

  26. 26

    How can I use the AngularJS hash option of $q.all?

  27. 27

    How can I use image form json response using angularjs?

  28. 28

    AngularJS - How can I use .config() method with my own services?

  29. 29

    How can I use HTML5 geolocation in angularjs

HotTag

Archive