1. Call the Element method angular.element(HTML) converts a string or DOM object into a jquery object,angular.element (document.getElementById ("Control")). Append (newhtml); In the ID of the control<div> element To add new objects, the new objects need to be $compile compiled before adding
<div ng-controller= "C10_1" class= "Frame" id= "Control" >
<button ng-click= "Add ()" > add element </button>
<button ng-click= "del ()" > Delete element </button>
</div>
<script type= "Text/javascript" >
Angular.module (' A10_1 ', [])
. Controller (' C10_1 ', function ($scope,$compile) {
$scope. Hello = ' hello,angular! ';
$scope. log = function () {
Console.log (' This is a dynamically added Method! ‘);
}//adding elements and their object methods plus variables
var html = "<div ng-click= ' log () ' >{{hello}}</div>";
var template =angular.element(HTML);
var newhtml =$compile(template) ($scope);
$scope. Add = function () {
Angular.element (document.getElementById ("Control")). Append (newhtml);
}
$scope. del = function () {
if (newhtml) {
Newhtml.remove ();
}
}
});
</script>
2. Using Ng-show
Cond
Angularjs Learning notes 2_ Adding delete DOM elements