Thursday, 12 September 2013

Passing the result of a function to a directive

Passing the result of a function to a directive

I have a list in controllerA - controllerA also has a function that
determines if an item in that list has been imported. I'd like to pass
this boolean into each of the listed objects' directives (so controllerB -
the controller for each of the objects - can see if its object has been
imported), but it's not working as I'd hoped.
I have the following (simplified) in my HTML:
<tbody>
<tr objectpane object="object"
objectIsImported="objectIsImported(object)"></tr>
</tbody>
This view is paired to an ng-controller (controllerA) that has the
following function defined:
$scope.objectIsImported = function(object) {
alert("never gets hit");
};
objectpane directive has this:
aoo.directive('objectpane', ['$log', function ($log) {
return {
restrict: 'A',
templateUrl: '/App/objectmanager/objectpane.html',
scope: {
object: "=",
objectIsImported: "="
},
controller: 'ObjectPaneController'
};
}]);
Within ObjectPaneController (ControllerB) I have this:
$scope.alreadyImported = $scope.objectIsImported; // from scope in directive
The problem is that the $scope.objectIsImported from controllerA is not
getting hit, ever. What am I doing wrong?

No comments:

Post a Comment