I am looking to use a controller function as an element attribute like so:
<div ng-app='myApp'>
<div ng-controller='myController as ctrl'>
<div {{ ctrl.choose_attribute() }}></div>
</div>
</div>
The choose_attribute
function will return a string that matches one of many directives. However, my rendered html looks like this:
<div ng-app='myApp'>
<div ng-controller='myController as ctrl'>
<div }}='' ctrl.choose_attribute()='' {{=''></div>
</div>
</div>
Am I approaching this the wrong way, or is there some trick to getting the return value to show up as an attribute?
Edit: It seems my choice of the word "attribute" was not that great, so here is an example directive that I am looking to create:
angular.module('myApp', [])
.controller('myController', function() {
this.choose_attribute = function () {
if (DataService.some_value == 'blah') {
return 'content1';
} else {
return 'content2';
}
};
})
.directive('content1', function() {
return {
restrict: 'A',
template: '<div>some content</div>'
};
})
.directive('content2', function() {
return {
restrict: 'A',
template: '<div>some other content</div>'
};
});