I don't see many mistakes in your code but it would have helped many to stop assuming only if you had posted your code sample link too.
But one primary change you have to make is : Change your directive definition function invoking from
.directive('questionDir', ["questionDir"])
to
.directive('questionDir', questionDir)
See this working fiddle which has just added questions.Cars
into $rootScope
to make answer look more relevant to your query.
To preserve content of your directive element :
What i see in your question is : Element <question-dir>
has child content / inner text print from direcetive
in it and it gets overridden by Directive Element <h1>Made by a directive!</h1>
completely.
That's the default nature of Angular : Element's (to which the directive is being applied) children will be lost to Directive Element. If you wanted to perserve the element's original content/children you would have to translude it.
Use transclude : true
in Directive Definition Object and add <div ng-transclude></div>
where you want directive Content / text print from direcetive
to be included.
Code snippet :
function questionDir() {
return {
transclude : true,
template: "<div ng-transclude></div><h1>Made by a directive!</h1>"
};
}
Check this one for transclude changes.
Check these 2 links for more information on Transclude :