Within my directive I have the following code, which will be used to continually append to an html element.
//Establishes the type of question and therefore
You should compile
the html to bind the directives
like ng-click
to scope properties. Other vice angular directives will not bind to the scope properties.
var strElm = '<button class="btn btn-info" ng-click="selectProperties()" title="Assign this user"><span class="glyphicon glyphicon-user"></span>Assignment</button>';
var compiledHtml = $compile(strElm);
element.append(compiledHtml);
and don't remove $compile
service from directive,
and your code should be like,
//Establishes the type of question and therefore what should be displayed
app.directive('questionType', function($http, $compile) {
return {
restrict: 'A',
link: function(scope, element, attr, model) {
switch (scope.Question.inputType) {
case 'checkbox':
//element.append('<input type="checkbox" ng-model="Question.checked"/><button ng-if="input.checked" >X</button>');
break;
case 'text':
var strElm = '<button class="btn btn-info" ng-click="selectProperties()" title="Assign this user"><span class="glyphicon glyphicon-user"></span>Assignment</button>';
var compiledHtml = $compile(strElm);
element.append(compiledHtml);
break;
}
}
};
});