angularjs - ng-include with ng-src not working -
i'm trying compile template has data-ng-include
, data-ng-src
defined. i'm trying set src calling getpartial()
, returns path of template. getpartial()
not getting called.
html:
<button ng-click="displayelements();">display elements</button> <div id="container"></div>
js:
$scope.displayelements = function() { var template = '<div data-ng-include data-ng-src="getpartial()"></div>'; var linkfn = $compile(template)($scope); //console.log(angular.element(document.getelementbyid("container"))); angular.element(document.getelementbyid("container")).append(linkfn); } $scope.getpartial = function() { console.log("from partial"); return 'hello.html'; }
'<div data-ng-include data-ng-src="getpartial()"></div>';
replace code this
'<div data-ng-include data-ng-init="getpartial()" src="htmltoload"></div>'; var app = angular.module('plunker', []); app.controller('mainctrl', ['$scope', '$compile', function($scope, $compile) { $scope.displayelements = function() { var template = '<div data-ng-include data-ng-init="getpartial()" src="htmltoload"></div>'; var linkfn = $compile(template)($scope); //console.log(angular.element(document.getelementbyid("container"))); angular.element(document.getelementbyid("container")).append(linkfn); } $scope.getpartial = function() { alert("sdfsdfsdf"); console.log("from partial"); return 'hello.html'; } }]);
Comments
Post a Comment