I ran into a strange behaviour on angular. when creating a directive if i use
mod.directive('test', [function(){
return {
restrict: 'E',
templateUrl: '/test/test.html',
transclude: true,
controller: ['$scope',function($scope){
//$scope equals containing scope of directive. why???
}]
};
}]);
$scope is the same scope (not inherited) as containing scope of directive.
but if i create directive as
mod.directive('test', [function(){
return {
restrict: 'E',
template: '<div><div ng-transclude /></div>',
transclude: true,
controller: ['$scope',function($scope){
//$scope is new. inherited from container scope
}]
};
}]);
only difference is template vs templateUrl. "templateUrl" one uses parent scope but "template" one creates a new scope. i dont understand why. could this be an angular bug?
thanks already
Edit: i am using Angular 1.3.0-beta.7
Big-Edit: i am using another directive on same element as @estus mentioned.
<test other-directive></test>
other-directive is defined as scope:true. but it doesn't create a new scope when used with templateUrl on test directive.
Edit: Sample plnkr http://plnkr.co/edit/Kghah1rvwFE6TSw85Cog?p=preview (templateUrl)
plnkr -> http://plnkr.co/edit/Axiye1ksBMR8dp9ND8tL?p=preview (template)