$compile showing uncaught TypeError: undefined is not a function


I am using the following code. To target the particular element and append a <div>inside that but getting uncaught typeerror: undefined is not a function for $compile(newDirective)($scope);

$scope.grid= function (targetElement) { console.log("target element",targetElement) var newDirective = angular.element("<div style='height:200px' > Sample code </div>"); targetElement.append(newDirective); $compile(newDirective)($scope); }


Try this code.

$scope.grid= function (targetElement) { var $div = $("<div style='height:200px' > Sample code </div>"); $(targetElement).append($div); angular.element(targetElement).injector().invoke(function($compile) { var scope = angular.element($div).scope(); $compile($div)(scope); }); }


  • Displaying unique transactions in Ruby on Rails
  • In a 5 day weather array how does one isolate a single time slot per day using swift?
  • simple html dom parser to return all td`s values?
  • To output a string without whitespce
  • cURL - works in browser, not in cURL
  • How to check payment method on a WooCommerce order by id?
  • How do I make powershell search a Word document for wildcards and return the word it found?
  • Android PICASSO - Image Not Loading into ImageView + Stops all Statements following from occuring
  • how to upload and download blackberry application from webserver?
  • How to make UI in blackberry including images in such a way that it works in different screen resolu
  • Escape input data in SQL queries when using ODBC + Access
  • SetHidden not working [duplicate]
  • RETROFIT how to parse this response
  • Property 'catch' does not exist on type 'PromiseLike
  • Why does this code crash on the distributed app but work in the debugger?
  • KoGrid JSON Dynamic widgets, with nested server calls
  • Cleave.js Phone CA
  • jQuery file download plugin
  • Can one add a complex type item to ListModel?
  • Understanding Intl.DateTimeFormat as a JavaScript object
  • JSON Error when parsing “… has no method 'replace'”
  • Getting error 'Cannot read property 'document' of undefined' while importing exp
  • why xml file does not aligned properly after append the string in beginning and end of the file usin
  • Groovy: Unexpected token “:”
  • Read text file and split every line in MSBuild
  • Accessing IRQ description array within a module and displaying action names
  • Javascript Callbacks with Object constructor
  • Shallow update not allowed (git > 1.9)
  • Where to put my custom functions in Wordpress?
  • Weird JavaScript statement, what does it mean?
  • jquery mobile loadPage not working
  • How to include full .NET prerequisite for Wix Burn installer
  • Qt: Run a script BEFORE make
  • Django query for large number of relationships
  • How to Embed XSL into XML
  • UserPrincipal.Current returns apppool on IIS
  • Conditional In-Line CSS for IE and Others?
  • Net Present Value in Excel for Grouped Recurring CF
  • jQuery Masonry / Isotope and fluid images: Momentary overlap on window resize
  • How to load view controller without button in storyboard?