Last Updated: June 29, 2023
· ydeshayes

Insert a new piece of code contain angularJS directive at runtime

You have to use $compile.

For example here, I insert new html code that contain angularjs directive (var fieldValue) in a new cell of a table.

var newCell = tblBodyObj.rows[i].insertCell(position);


$compile(fieldValue)($scope) return an object and you can append it to the dom.

1 Response
Add your response

Yes you're right, if you're calling this function out of a angularjs function/context, then you need to call $scope.apply() after compile.

over 1 year ago ·