Here is a fiddle representing my problem: https://jsfiddle.net/m9t7ew8j/1/
The essential part of the code that matters is the following:
.directive('firstDirective', [function () {
return {
restrict: 'E',
template: '<div>This is a directive.
Here is a scope variable
pre-defined: {{name}} </div>', // <---- this is the problem
controller: ['$q', function ($q) {
var vm = this;
vm.name = 'something';
}]
}
}])
Basically, the controller has no name because it's an inline-controller, so how do I represent it in the template attribute? Do I have to actually declare the controller like the following?
.controller('secondController', [function(){
var vm = this;
vm.name = 'John Snow';
}])
.directive('secondDirective', [function(){
return {
restrict: 'E',
template: '<div>This is a directive.
Here is a scope variable
pre-defined: {{vm.name}} </div>', // <- declaring as vm.name will work
controller: 'secondController as vm'
}