How add element to div in angularjs?

Emil

i want to add element to div in angularjs. so write this code but not work correctly. thanks for your help :)

function TestController($scope) {
$scope.addElement = function(){
    var myElements = angular.element(document.querySelector('#form'));
    console.log(myElements);
    if(myElements.length == 0)
     alert("Not Find");
    else
        myElements.prepend( myElements[0].children[1]);
}
}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app ng-controller="TestController" id="form">
    <input type="button" ng-click="addElement()" value="add"></input>
    <div id="div">
      <input type="text" name="name">
   </div>
</div>

RIYAJ KHAN

Here is what I have tried.

$scope.addElement = function(){
    var myElements = angular.element(document.querySelector('#form'));
    console.log(myElements)

   console.log(myElements[0].children[1])
    if(myElements.length == 0)
     alert("Not Find");
    else{
        html = angular.element(myElements[0].children[1]).clone();  
        myElements.append( html);
    }

You should use angular clone method.

EDIT.

Here it the Plunker

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to append div element onclick in angularjs

From Dev

How to append div element onclick in angularjs

From Dev

How to dynamically add a directive to an input element in AngularJS

From Dev

Add a div element dynamically in ng-repeat angularjs

From Dev

How to add div with a button click in angularJs

From Dev

AngularJS: How to add label from checkbox to div

From Dev

How to capture and add keystrokes to a div element in realtime?

From Dev

How to add canvas to div element dynamically?

From Dev

How to add marquee element with text to a div in javascript

From Dev

Add a directive to an element with AngularJS?

From Dev

How to add a class to an element and remove to the others siblings in AngularJS

From Dev

How do I add a class on click to a parent element in AngularJS?

From Dev

How do I add a delay for hovering an element in angularjs?

From Dev

How do I add a class on click to a parent element in AngularJS?

From Dev

How to add and remove a class if another element is clicked in AngularJS?

From Dev

How to add a class to an element and remove to the others siblings in AngularJS

From Dev

How to add HTML element inside of exist div, but cover content?

From Dev

How can I add an on click event on a div with multiple element inside

From Dev

How can I add an on click event on a div with multiple element inside

From Dev

How to add HTML element inside of exist div, but cover content?

From Dev

Dynamically add element using angularJS

From Dev

Add angularjs directive to a native html element (input text, div, span etc)?

From Dev

How can I get text value of a <div> element and displaying it in another div using ng click in AngularJS

From Dev

Add element to div in a relative position

From Dev

Add element to div in a relative position

From Dev

Javascript add element to a dynamic div

From Dev

how to add transclude in angularjs

From Dev

How to sandbox a div element?

From Dev

add a start div tag to the element and end div tag to another element

Related Related

  1. 1

    How to append div element onclick in angularjs

  2. 2

    How to append div element onclick in angularjs

  3. 3

    How to dynamically add a directive to an input element in AngularJS

  4. 4

    Add a div element dynamically in ng-repeat angularjs

  5. 5

    How to add div with a button click in angularJs

  6. 6

    AngularJS: How to add label from checkbox to div

  7. 7

    How to capture and add keystrokes to a div element in realtime?

  8. 8

    How to add canvas to div element dynamically?

  9. 9

    How to add marquee element with text to a div in javascript

  10. 10

    Add a directive to an element with AngularJS?

  11. 11

    How to add a class to an element and remove to the others siblings in AngularJS

  12. 12

    How do I add a class on click to a parent element in AngularJS?

  13. 13

    How do I add a delay for hovering an element in angularjs?

  14. 14

    How do I add a class on click to a parent element in AngularJS?

  15. 15

    How to add and remove a class if another element is clicked in AngularJS?

  16. 16

    How to add a class to an element and remove to the others siblings in AngularJS

  17. 17

    How to add HTML element inside of exist div, but cover content?

  18. 18

    How can I add an on click event on a div with multiple element inside

  19. 19

    How can I add an on click event on a div with multiple element inside

  20. 20

    How to add HTML element inside of exist div, but cover content?

  21. 21

    Dynamically add element using angularJS

  22. 22

    Add angularjs directive to a native html element (input text, div, span etc)?

  23. 23

    How can I get text value of a <div> element and displaying it in another div using ng click in AngularJS

  24. 24

    Add element to div in a relative position

  25. 25

    Add element to div in a relative position

  26. 26

    Javascript add element to a dynamic div

  27. 27

    how to add transclude in angularjs

  28. 28

    How to sandbox a div element?

  29. 29

    add a start div tag to the element and end div tag to another element

HotTag

Archive