Someone created custom tag in the project, such as
<mytable config='{head:[title1, title2],data:[[col1, col2]]}'></mytable>
,
the tag above will generate a table after the page is loaded.
I want to create a button in the table, then I insert the string :
'<button class="btn btn-primary" ng-click="lookup(3)">lookup</button>';
but the ng-click doesn't work. I write a simple code to mock it:
<!DOCTYPE html>
<html ng-app="myApp">
<head>
<script type="text/javascript" src="/javascripts/jquery.min.js"></script>
<script type="text/javascript" src="/javascripts/angular/1.4.0/angular.min.js"></script>
<script>
var create = function () {
$('#template').html('<button ng-click="changeName()">click me</button>')
}
</script>
</head>
<body ng-controller="myCtrl">
<span>{{name}}</span>
<div id="template"></div>
<button onclick="create()">create</button>
<script>
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
$scope.name = "John";
$scope.changeName = function () {
$scope.name = "Jack";
alert("success");
}
});
</script>
</body>
</html>
I have googled and find the angular should compile the newly created element, but I don't know how to in this situation