Check out this code snippet I wrote using Angular 1.2: http://jsfiddle.net/VmkQy/1/
<div ng-app="app">
Title is: <span my-directive data-title="Test title">{{ title }}</span>
</div>
angular.module('app', [])
.directive('myDirective', [function() {
return {
restrict: 'A',
scope: {title:'@'},
link: function($scope) {
alert($scope.title);
}
}
}])
;
I have a title
property in the scope, but it doesn't render. Why is that?
When I change the directive configuration to scope:true
, everything works perfectly: http://jsfiddle.net/VmkQy/2/
angular.module('app', [])
.directive('myDirective', [function() {
return {
restrict: 'A',
scope: true,
link: function($scope, $element, attrs) {
$scope.title = attrs.title;
alert($scope.title);
}
}
}])
;
Is this a bug or a feature specific to Angular 1.2? Older versions seem to handle these cases fine: http://jsfiddle.net/VmkQy/3/