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);
$(newCell).append($compile(fieldValue)($scope));
$compile(fieldValue)($scope) return an object and you can append it to the dom.
Written by Deshayes Yann
Related protips
1 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
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Tips
Authors
Did you know?
JavaScript on a page runs with the privileges of that origin. One altered library, tag manager, or snippet can read inputs, change what people see, and call your APIs as the user.
Security insights from Cside
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#