我有一个这样的指令:
'use strict';
angular.module('epw')
.directive('md-title', function ($rootScope) {
return {
scope: {
listenTo: '@'
},
controller: function () {
$rootScope.$on('event', function (e, msg) {
console.log('do something');
}); // how to I dynamically change what to listen to using the scope `listenTo`
},
controllerAs: 'ctrl',
bindToController: true,
templateUrl: 'md-title.html'
}
});
我有这个:
<md-title listen-to="TITLE_SELECTION_UPDATED"></md-title>
和
<div class="m-section-header">
<h1 class="epw-header">{{ctrl.title}}</h1>
</div>