angularjs-compile

Angular $compile with required controller

烂漫一生 提交于 2019-12-03 11:00:59
I have a composite list directive - that is - a list item that can be a list himself. The parent directive defines the controller: .directive('parent', function() { controller: function($scope) { }, link: function (scope, element, attrs) { } }) The list (of items) requires the parent controller which by itself works fine (why shouldn't it..): .directive('list', function() { require: '^parent', link: function (scope, element, attrs, parentCtrl) { } }) The same goes as well for the concrete item, which is also fine: .directive('item', function() { require: '^parent', link: function (scope,

Working with $compile in angularjs

社会主义新天地 提交于 2019-12-03 09:10:51
I am really confused with $compile in angularjs. can anyone help me, What use of $compile in angularjs with an example other then in this documentation. https://docs.angularjs.org/api/ng/service/$compile $compile just compile the text to html.. Here is sample example angular .module("myModule", []) .controller("myController", ['$scope', '$compile', function ($scope, $compile) { $scope.txt = "<b>SampleTxt</b>"; $scope.submit = function () { var html = $compile($scope.txt)($scope); angular.element(document.getElementById("display")).append(html); } }]); <script src="https://ajax.googleapis.com

Can I get the compiled html of an Angular element?

末鹿安然 提交于 2019-11-30 08:27:09
问题 I have compiled an element using the $compile service. If I add that directly to the DOM, it looks great and all of the bindings are correct. If I want that element as a string though, it shows {{stuffHere}} instead of the bindings. Is there a way to get the html of the element after it's compiled? $templateCache.put('template', '<div><div><div><span>content is {{content}}</span></div></div> </div>'); $scope.content = 'Hello, World!'; var el = $compile($templateCache.get('template'))($scope);

Can I get the compiled html of an Angular element?

瘦欲@ 提交于 2019-11-29 06:36:56
I have compiled an element using the $compile service. If I add that directly to the DOM, it looks great and all of the bindings are correct. If I want that element as a string though, it shows {{stuffHere}} instead of the bindings. Is there a way to get the html of the element after it's compiled? $templateCache.put('template', '<div><div><div><span>content is {{content}}</span></div></div> </div>'); $scope.content = 'Hello, World!'; var el = $compile($templateCache.get('template'))($scope); $('body').append(el); alert(el.html()); http://plnkr.co/edit/1sxvuyUZKbse862PieBa?p=preview The