i am new in angular and that why i do not know the scenario like when one should declare controller inside directives.
see one sample code
<body ng-app="App">
<div ng-controller="AppCtrl">
<div data-items></div>
</div>
</body>
angular.module('App', []).
// sample data
controller('AppCtrl', function($scope){
$scope.items =[
{'title': 'Item 3'},
{'title': 'Item 2'},
{'title': 'Item 1'}
]
}).
directive('items', function(){
return {
template: '<span ng-repeat="item in items">{{item.title}}</span>'+
'<h1>{{currentItem}}</h1>',
controller: function($scope, orderByFilter){
$scope.items = orderByFilter($scope.items, 'title',false);
$scope.currentItem = $scope.items[0].title;
}
}
})
in the above code there is one directive called items and there must notice one controller too. just tell me in easy way when we have to declare controller inside directive?
what kind of purpose controller inside directive solve ? please me to understand the significant of declaring controller inside directive. thanks