I have a scope in my main controller, and then I feed in an isolate scope into my link function. Is there any way to also access the main scope from my link function? Here's a simplified version of what I'm trying to do:
Angular:
angular.module('root', [])
.controller('index', ['$scope', function($scope){
$scope.messages = ["Hello", "Howdy", "What's up"]
}
.directive('myDirective', function() {
return {
restrict: 'E',
scope: { greeting: '=' },
link: function(scope, element, attrs) {
var greeting = scope.greeting; //one message from the array, fed in by <my-directive greeting='message'> from index.html
var length = scope.messages.length; //length of whole messages array
//do stuff
}
}
}
HTML: (index.html)
<body ng-app='root' ng-controller='index'>
<div ng-repeat='message in messages'>
<my-directive greeting='message'></my-directive>
</div>
</body>
I want to be able to access both the message and the "meta" information about the entire messages array from my link function. However, right now I can only access the message (var greeting) but the length variable does not evaluate. Is there a way to do this in angular?
Let me know if you need any other clarifications!