I have a directive that has a controller with a $http call to an endpoint. I'd like to take the results of that server call and then display them in my template. If I have a single value inside my template, and then set it explicitly, it all works fine. If I try to bind the template to the server call then I get the error mentioned above. Do I need to use the $compile service for this to work?
thanks in advance
Final result with compilation
function mydirective(myservice,$compile) {
return {
restrict: 'ACE',
scope: {
url: '=',
title: '=',
},
controllerAs: 'ctrl',
bindToController: true,
controller: ['$scope', function($scope) {
myservice.init('http://jsonplaceholder.typicode.com/posts')
.then(function(data) {
$scope.postRequest(data);
});
$scope.postRequest = function(val) {
this.items = val;
this.title = val[0].title;
};
}],
link: function ($scope, $el, $attr ) {
var template = '<div class=\"test\">{{this.title}}</div>' +
'<div class=\"tes\" ng-repeat=\"item in this.items\">'+
'<div class=\"test1\">{{item.title}}</div>'+
'</div>';
var e = $compile(template)($scope);
$el.after(e);
}
};
}