angular element code example

Example 1: get all html element data using angular

File your-component-name.component.html

<input type="text" #inputbox>
<button type="submit" (click)="getelementData()">Show element data</button>

file your-component-name.component.ts
In the class make function named as 

getelementData(nameinput){
 console.log(nameinput);  // output will be the whole button element with their attributes
 // if you want to show specific attribute data then 
 console.log(nameinput.value);  // it will reflects the value of textbox which has been entered
}

Example 2: angularjs class directive prepend

app.directive("otcDynamic", function($compile) {
     
    var template = "<button ng-click='doSomething()'>{{label}}</button>";
     
    return{
        link: function(scope, element){
            element.on("click", function() {
                scope.$apply(function() {
                    var content = $compile(template)(scope);
                    element.append(content);
               })
            });
        }
    }
});

Tags:

Html Example