1

Before you answer my question please consider that I am using AngularJS 1 with TYPESCRIPT.

Does any body know how to bind a controller function to cell template like asked in this link using Angular UI Grid?

I have got a very similar situation, where I define custom cell template containing buttons and try to bind the ng-click directive to a function in the controller?

So I just have something like this:

Component template:

<div id="grid1" ui-grid="$ctrl.gridOptions" class="grid" external-scopes="ctrl"></div>

Component controller (just some code snippets):

ctrl = this;

exampleFunction() {
    console.log("Example function called.");
}

actionsCellTemplate = 
            '<btn class="btn btn-default action-button" ng-click="getExternalScopes().exampleFunction()">' +
                '<i class="icon-blue"><b>...</b></i>' +
            '</btn>';

columnDefs: [ { displayName: '', field: 'actions', enableColumnMenu: false, cellTemplate: this.actionsCellTemplate } ]

I DO NOT get any errors in the browser console.

2
  • is exampleFunction() part of the scope? Or is it just defined inside controller? Also, have you tried ng-click="grid.appScope.exempleFunction()"? Commented Apr 27, 2017 at 9:28
  • 1
    I don't use scope at all. just write my fields and methods in controller and access them using $ctrl. syntax in the html template -> what works pretty well. The grid.appScope.exempleFunction() does not work. Commented Apr 27, 2017 at 9:29

1 Answer 1

1

External scopes are no longer supported in ui-grid since RC 19. https://github.com/angular-ui/ui-grid/blob/master/CHANGELOG.md#breaking-changes

getExternalScopes() function is removed. Use grid.appScope instead. external-scopes attribute is removed. Use gridOptions.appScopeProvider to assign values other than $scope.$parent to appScope

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.