Sign up ×
Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them, it only takes a minute:

I have a chain directive with angularJS and ES6 and want to use ui-grid. The grid is shown with the correct columns and data, thats fine.

But ng-click don´t work in the cellTemplate. Nothing happens. Also i try to check the grid object with console.log(grid) and grid is undefined.

Who can i use the cellTemplate to call the openDetail method?

export default function ChainsDirective() {
    class ChainsDirective {

        /*@ngInject*/
        constructor(chainsService, $state) {
            this.chainsServiceLoadChains = chainsService.loadChains.bind(chainsService);
            this.gridOptions = {
                enableColumnMenus: false,
                columnDefs: [
                    {
                        name: 'id',
                        visible: false
                    },
                    {
                        name: 'name',
                        displayName: 'Kette',
                        cellTemplate: '<div class="ui-grid-cell-contents"><a onclick="console.log(grid)" ng-click="grid.appScope.openDetail(row.entity.id)">{{row.entity.name}}</a></div>'
                    }
                ]
            };
            this.$stateGo = $state.go.bind($state);
            this.fetch(); // best practice initiales laden in einer Funktion zu kapseln
        }

        /**
         * @param int chainId
         */
        openDetail(chainId) {
            this.$stateGo('chainDetail', {chainId})
        }

        fetch() {
            return this.chainsServiceLoadChains().then(data => {
                this.gridOptions.data = data;
            })
        }
    }

    return {
        restrict: 'E',
        template: '<div ui-grid="chains.gridOptions" external-scopes="$scope" class="grid"></div>',
        scope: {},
        bindToController: {},
        controller: ChainsDirective,
        controllerAs: 'chains'
    }
}
share|improve this question

1 Answer 1

up vote 0 down vote accepted

I've never used ui-grid directive. But it seems that you need to access your controller by its name, since you have declared it with the "controller as" syntax.

So in your ng-click you need to reference the controller on the scope with its name chains:

ng-click="grid.appScope.chains.openDetail(row.entity.id)"
share|improve this answer
    
Thanks, it works... – Thorsten Rintelen Oct 21 at 7:17

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.