ng-table icon indicating copy to clipboard operation
ng-table copied to clipboard

Can't access scope inside header template inside component

Open ghost opened this issue 7 years ago • 6 comments

working demo with controller-as syntax: http://ng-table.com/#/formatting/demo-header-cell-full my demo with angular component http://plnkr.co/edit/IOJZfWFlJEWo93PWX4Xl?p=preview Seems like custom template headerCheckbox.html can't get access to $ctrl variable

I hope author still works on this plugin. It's really great and it's my first problem with it.

ghost avatar Mar 26 '17 07:03 ghost

Hello @maxkorz, Did you finally made it work ? I'm facing the exact same problem right now :/ Regards

renaud-dev avatar May 15 '17 13:05 renaud-dev

@renaudaste hi. Sorry, but no luck there. I gave up on this idea.

ghost avatar May 15 '17 14:05 ghost

Thank you for your quick answer, I also couldn't find any solution. But will be back on this thread when I make it work.. Well, hopefully :)

renaud-dev avatar May 15 '17 22:05 renaud-dev

@renaudaste I also ran to this problem and solved it in the ugly way.

my.html

<script type="text/ng-template" id="headerCheckbox.html">
  <input type="checkbox" ng-model="bindings.ctrl.checked" class="select-all" value="" />
</script>
<div ng-bind="$ctrl.checked"></div>

...

myComponent.js

function myController($scope) {
  $scope.bindings = { ctrl: this };
}

angular.module("my-project").component("my", {
  templateUrl: "my.html",
  controller: myController,
});

What I have done is binding the component's controller to its scope and call it inside child's scope since child's inherit from parent's. I think the reason we cannot use $ctrl in there is because it is reserved for its own scope (child's scope).

A nicer solution would be nice though.

mixth avatar Jun 14 '17 04:06 mixth

https://github.com/esvit/ng-table/issues/917 worked "fine" for me.

kevinboosten avatar Jun 19 '17 13:06 kevinboosten

I have met the same problem, any elegant solution?

huizhoujava avatar Jan 17 '19 11:01 huizhoujava