This repository was archived by the owner on Apr 12, 2024. It is now read-only.
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
"Return" in directive's controllers no longer works in 1.3.0-rc.0 #8876
Closed
Description
I used to use return
in my directive's controllers, but it stopped working in 1.3.0-rc.0.
For example, here is how I used to write a directive:
angular.module('MyApp', []).directive('test', ['$rootScope', function($rootScope) {
return {
restrict: 'AE',
replace: true,
transclude: true,
template: '<div>test: {{ test }}</div>',
controller: ['$scope', '$element', '$attrs', function($scope, $element, $attrs) {
return {
register: function() {
$scope.test = 'it works';
}
};
}],
link: function($scope, $element, $attrs, testCtrl) {
testCtrl.register();
}
};
}]);
But now testCtrl
in the link function returns an empty object {}.
I fixed my directives by using this
but I'm not sure why the return doesn't work anymore ?
Here is how I had to write it:
angular.module('MyApp', []).directive('test', ['$rootScope', function($rootScope) {
return {
restrict: 'AE',
replace: true,
transclude: true,
template: '<div>test: {{ test }}</div>',
controller: ['$scope', '$element', '$attrs', function($scope, $element, $attrs) {
this.register = function() {
$scope.test = 'it works';
};
}],
link: function($scope, $element, $attrs, testCtrl) {
testCtrl.register();
}
};
}]);
Here is the plnkr: http://plnkr.co/edit/sSJGIQIM2D9vIZmD42ya?p=preview