Click here to Skip to main content
15,895,011 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hey,

I have directive (with own controller) within other controler like this:

XML
<div id="Test-content" ng-controller="testCtrl">
    <oa-modal-dialog dialog-title="This is example dialog" dialog-state="true" dialog-on-open="" dialog-on-close="test.close()" dialog-type="warning" dialog-size="small" dialog-top-toolbar="" dialog-bottom-toolbar=""></oa-modal-dialog>
</div>



Test controller:
PHP
.controller('testCtrl', ['$scope', function ($scope) {

    $scope.test = {
        close: function() {
            console.log('test');
        }
    };

}])


Modal dialog directive:
C#
.directive('oaModalDialog', function () {
    return {
        restrict: 'E',
        transclude: true,
        link: function(scope, element, attrs) {
            attrs.$observe('dialogState', function (value) {
                scope.dialogState = value;
            });
        },
        templateUrl: 'oaModalDialogs.html',
        controller: 'modalDialogsCtrl'
    }
});



Question how can I retrieve and fire function which is in directives attribute 'dialog-on-close' in directives controller 'modalDialogs'? Presume that any function can be included into attribute so I can't use fixed function ($scope.test.close() in the controller)

I tried something like this:
JavaScript
.controller('modalDialogsCtrl', ['$scope', '$element', '$attrs', function ($scope, $element, $attrs) {
$attrs['dialogOnClose']();
}]);

Throws error... Any suggestions?
Posted

1 solution

Sorted this using funtion: eval

eval('$scope.' + $attrs['dialogOnClose']+'();');
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900