Html code:
<div class="test">{{name}}</div>
Angular code:
var app = angular.module('angularjs-starter', []);
app.controller('MainCtrl', function($scope) {
$scope.name = 'World';
});
app.directive('test', function(){
return {
restrict: 'C',
link: function(scope, elm, attrs){
var content = elm.html();
alert(content);
}
}
});
It will alert a string {{name}}. How to alert the rendered string World?
Live demo: http://plnkr.co/edit/Mov0AlkdE9B8yKiBjpnp?p=preview
You need to use $interpolate service to do this
app.directive('test', function($interpolate){
return {
restrict: 'C',
link: function(scope, elm, attrs){
var content = elm.html();
alert($interpolate(content)(scope))
}
}
});
Demo: Fiddle