kenza kenza - 1 year ago 69
AngularJS Question

append a html include ng-click in angularjs

i have this code in mycontroller i will add this

to my html, all it right just ng-click dos not work ! have you an ideas why ng-click dos not work

var html='<div ng-click="selectedValue('+Value+')">Value</div>' ;

$scope.selectedValue = function(value){
$scope.val =value;


i have to slect the value displayed in the div by using ng-click function selectedValue

Answer Source

use this code:

See pluker


var html='<div ng-click="selectedValue(value)">Value</div>',
    el = document.getElementById('myID');


angular.element(el).append( $compile(html)($scope) )

$scope.selectedValue = function (value) {
    $scope.val = value;


<body ng-controller="MainCtrl">
    <div id="myID"></div>