Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't bind to property on ngx-datatable with attribute directive #652

Open
DeezCashews opened this issue Mar 30, 2017 · 1 comment
Open

Comments

@DeezCashews
Copy link

I'm submitting a ... (check one with "x")
I've seen similar issues but OP is either misusing, or abandons post and it gets closed.

[x] bug report => search github for a similar issue or PR before submitting
[ ] feature request
[ ] support request => Please do not submit support request here

Current behavior
@HostBinding throws errors for properties that are clearly on DatatableComponent

Expected behavior
@HostBinding('rows') rows = ... would pass rows into DatatableComponent

Reproduction of the problem
https://plnkr.co/edit/3Un9JvZIqLQ9KL1ETmuM

What is the motivation / use case for changing the behavior?
Allowing defaults to be set or custom loaders to be added to a ngx-datatable via directive instead of having to wrap it in another component. In my case, my external paging/sorting is handled the exact same way across the application.

Please tell us about your environment:
Windows 7, VSCode, yarn/npm, undertow/tomcat

  • Table version: 0.7.x
    current, see plunkr

  • Angular version: 2.0.x
    current, see plunkr

  • Browser: [all | Chrome XX | Firefox XX | IE XX | Safari XX | Mobile Chrome XX | Android X.X Web Browser | iOS XX Safari | iOS XX UIWebView | iOS XX WKWebView ]
    Chrome

  • Language: [all | TypeScript X.X | ES6/7 | ES5]
    Typescript 2.2.1

@adammedford
Copy link

adammedford commented Mar 30, 2017

To my knowledge this concerns Angular's compiler and is not unique to this library. The reason ngx-datatable doesn't have that property is because it is referring to ngx-datatable the DOM element, not the component. If you want that behavior then you need to submit a request on the Angular repo.

You don't need HostBinding to set defaults on components using directives. Angular will inject a reference to the DatatableComponent in your constructor (which you obviously included in your plunker.)

Why do you want to try and use directives to set the values of input properties when you can just do this in your directive?:

constructor(public datatable: DatatableComponent) {
  }

@Input() customData; // an object containing relevant properties like rowHeight, footerHeight, limit, etc

ngOnChanges(changes) {
 if ('customData' in changes) {
 Object.assign(this.datatable, this.customData);
}
}

Or to use your example:
https://plnkr.co/edit/gJ0MnCnBKKWBqGYMMsio?p=preview

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants