RobVious
RobVious

Reputation: 12915

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>

objectIsImported is supposed to be passing a boolean down to the objectPane instance.

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? Everything else is working between the controllers / directive, it's just that passing this function result down to the directive doesn't seem to be working.

Upvotes: 0

Views: 60

Answers (1)

Martin
Martin

Reputation: 8866

The attribute objectIsImported should be changed to lowercase with hyphens: object-is-imported.

Upvotes: 1

Related Questions